summaryrefslogtreecommitdiffstats
path: root/services/tests
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2010-03-19 16:57:21 -0700
committerNick Kralevich <nnk@google.com>2010-03-19 16:57:21 -0700
commit93a68398b661c02d6c417a2a04e64a6750a9a119 (patch)
treef8a9d195781f95f682202e1cf979abcf0646095e /services/tests
parenta0a59122ebb7f1c134e8b8f9c0c90b7d90b86279 (diff)
downloadframeworks_base-93a68398b661c02d6c417a2a04e64a6750a9a119.zip
frameworks_base-93a68398b661c02d6c417a2a04e64a6750a9a119.tar.gz
frameworks_base-93a68398b661c02d6c417a2a04e64a6750a9a119.tar.bz2
Unittests for EntropyService. Make EntropyService more testable.
I've been meaning to write these tests for a long time... Use "runtest frameworks-services" to run these tests. Change-Id: I3a3cb7eda547f4a790f38be884b4a583426c7326
Diffstat (limited to 'services/tests')
-rw-r--r--services/tests/servicestests/src/com/android/server/EntropyServiceTest.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/services/tests/servicestests/src/com/android/server/EntropyServiceTest.java b/services/tests/servicestests/src/com/android/server/EntropyServiceTest.java
new file mode 100644
index 0000000..636ba21
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/EntropyServiceTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server;
+
+import android.content.Context;
+import android.os.FileUtils;
+import android.test.AndroidTestCase;
+
+import java.io.File;
+
+/**
+ * Tests for {@link com.android.server.EntropyService}
+ */
+public class EntropyServiceTest extends AndroidTestCase {
+
+ public void testInitialWrite() throws Exception {
+ File dir = getContext().getDir("testInitialWrite", Context.MODE_PRIVATE);
+ File file = File.createTempFile("testInitialWrite", "dat", dir);
+ file.deleteOnExit();
+ assertEquals(0, FileUtils.readTextFile(file, 0, null).length());
+
+ // The constructor has the side effect of writing to file
+ new EntropyService("/dev/null", file.getCanonicalPath());
+
+ assertTrue(FileUtils.readTextFile(file, 0, null).length() > 0);
+ }
+}