aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SortTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-03-07 03:39:23 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-03-07 03:39:23 +0000
commit5e5adfd12cc2cb194db971708cd7f34ff47e10b4 (patch)
tree4a516106bdc5844e275d6d2bcd03dfea80936828 /tests/SortTest.cpp
parent62533ed6bb490e9abf5d02686d897a93c5e85d51 (diff)
migrate more legacy unittests into tests/
SkParse yet to be cleaned up git-svn-id: http://skia.googlecode.com/svn/trunk@113 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/SortTest.cpp')
-rw-r--r--tests/SortTest.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/SortTest.cpp b/tests/SortTest.cpp
new file mode 100644
index 0000000000..6d287c5004
--- /dev/null
+++ b/tests/SortTest.cpp
@@ -0,0 +1,30 @@
+#include "Test.h"
+#include "SkRandom.h"
+#include "SkTSearch.h"
+
+extern "C" {
+ int compare_int(const void* a, const void* b) {
+ return *(const int*)a - *(const int*)b;
+ }
+}
+
+static void TestSort(skiatest::Reporter* reporter) {
+ int array[100];
+ SkRandom rand;
+
+ for (int i = 0; i < 1000; i++) {
+ int j, count = rand.nextRangeU(1, SK_ARRAY_COUNT(array));
+ for (j = 0; j < count; j++) {
+ array[j] = rand.nextS() & 0xFF;
+ }
+ SkQSort(array, count, sizeof(int), compare_int);
+ for (j = 1; j < count; j++) {
+ REPORTER_ASSERT(reporter, array[j-1] <= array[j]);
+ }
+ }
+}
+
+// need tests for SkStrSearch
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Sort", SortTestClass, TestSort)