diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-02-27 16:24:51 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-02-27 16:24:51 +0000 |
commit | ed673310e2551e64d8196f7776d7d4c92085f8c2 (patch) | |
tree | ac5a737aaaf66c97be7109eb980beadd35e30e25 /src/core/SkUtils.cpp | |
parent | 3469c76c40790b409621fd7eff34f56240718549 (diff) |
add initial unittest framework (tests)
move some previous unittests out of core classes and into tests
git-svn-id: http://skia.googlecode.com/svn/trunk@96 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkUtils.cpp')
-rw-r--r-- | src/core/SkUtils.cpp | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/src/core/SkUtils.cpp b/src/core/SkUtils.cpp index a4c6c16cd1..edc5b74954 100644 --- a/src/core/SkUtils.cpp +++ b/src/core/SkUtils.cpp @@ -458,126 +458,3 @@ SkAutoMemoryUsageProbe::~SkAutoMemoryUsageProbe() #endif } -//////////////////////////////////////////////////////////////////////////////////// - -#ifdef SK_DEBUG - -#include "SkRandom.h" -#include "SkTSearch.h" -#include "SkTSort.h" - -#define kSEARCH_COUNT 91 - -#ifdef SK_SUPPORT_UNITTEST -static void test_search() -{ - int i, array[kSEARCH_COUNT]; - SkRandom rand; - - for (i = 0; i < kSEARCH_COUNT; i++) - array[i] = rand.nextS(); - - SkTHeapSort<int>(array, kSEARCH_COUNT); - // make sure we got sorted properly - for (i = 1; i < kSEARCH_COUNT; i++) - SkASSERT(array[i-1] <= array[i]); - - // make sure we can find all of our values - for (i = 0; i < kSEARCH_COUNT; i++) - { - int index = SkTSearch<int>(array, kSEARCH_COUNT, array[i], sizeof(int)); - SkASSERT(index == i); - } - - // make sure that random values are either found, or the correct - // insertion index is returned - for (i = 0; i < 10000; i++) - { - int value = rand.nextS(); - int index = SkTSearch<int>(array, kSEARCH_COUNT, value, sizeof(int)); - - if (index >= 0) - SkASSERT(index < kSEARCH_COUNT && array[index] == value); - else - { - index = ~index; - SkASSERT(index <= kSEARCH_COUNT); - if (index < kSEARCH_COUNT) - { - SkASSERT(value < array[index]); - if (index > 0) - SkASSERT(value > array[index - 1]); - } - else // we should append the new value - { - SkASSERT(value > array[kSEARCH_COUNT - 1]); - } - } - } -} - -static void test_utf16() -{ - static const SkUnichar gUni[] = { - 0x10000, 0x18080, 0x20202, 0xFFFFF, 0x101234 - }; - - uint16_t buf[2]; - - for (unsigned i = 0; i < SK_ARRAY_COUNT(gUni); i++) - { - size_t count = SkUTF16_FromUnichar(gUni[i], buf); - SkASSERT(count == 2); - size_t count2 = SkUTF16_CountUnichars(buf, 2); - SkASSERT(count2 == 1); - const uint16_t* ptr = buf; - SkUnichar c = SkUTF16_NextUnichar(&ptr); - SkASSERT(c == gUni[i]); - SkASSERT(ptr - buf == 2); - } -} - -#endif - -void SkUtils::UnitTest() -{ -#ifdef SK_SUPPORT_UNITTEST - static const struct { - const char* fUtf8; - SkUnichar fUni; - } gTest[] = { - { "a", 'a' }, - { "\x7f", 0x7f }, - { "\xC2\x80", 0x80 }, - { "\xC3\x83", (3 << 6) | 3 }, - { "\xDF\xBF", 0x7ff }, - { "\xE0\xA0\x80", 0x800 }, - { "\xE0\xB0\xB8", 0xC38 }, - { "\xE3\x83\x83", (3 << 12) | (3 << 6) | 3 }, - { "\xEF\xBF\xBF", 0xFFFF }, - { "\xF0\x90\x80\x80", 0x10000 }, - { "\xF3\x83\x83\x83", (3 << 18) | (3 << 12) | (3 << 6) | 3 } - }; - - for (unsigned i = 0; i < SK_ARRAY_COUNT(gTest); i++) - { - const char* p = gTest[i].fUtf8; - int n = SkUTF8_CountUnichars(p); - SkUnichar u0 = SkUTF8_ToUnichar(gTest[i].fUtf8); - SkUnichar u1 = SkUTF8_NextUnichar(&p); - - SkASSERT(n == 1); - SkASSERT(u0 == u1); - SkASSERT(u0 == gTest[i].fUni); - SkASSERT(p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8)); - } - - test_utf16(); - - test_search(); -#endif -} - -#endif - - |