Port SkBase64 test to our test driver.
authortfarina@chromium.org <tfarina@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 30 Jan 2014 22:51:42 +0000 (22:51 +0000)
committertfarina@chromium.org <tfarina@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 30 Jan 2014 22:51:42 +0000 (22:51 +0000)
BUG=None
TESTS=tests --match SkBase64Test
R=mtklein@google.com, reed@google.com

Review URL: https://codereview.chromium.org/132233060

git-svn-id: http://skia.googlecode.com/svn/trunk@13254 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/tests.gyp
src/utils/SkBase64.cpp
src/utils/SkBase64.h
tests/SkBase64Test.cpp [new file with mode: 0644]

index 2edb03f..827ba3f 100644 (file)
       ],
       'sources': [
         '../tests/AAClipTest.cpp',
+        '../tests/ARGBImageEncoderTest.cpp',
         '../tests/AndroidPaintTest.cpp',
         '../tests/AnnotationTest.cpp',
-        '../tests/ARGBImageEncoderTest.cpp',
         '../tests/AtomicTest.cpp',
-        '../tests/BitmapTest.cpp',
+        '../tests/BitSetTest.cpp',
         '../tests/BitmapCopyTest.cpp',
         '../tests/BitmapGetColorTest.cpp',
         '../tests/BitmapHasherTest.cpp',
         '../tests/BitmapHeapTest.cpp',
-        '../tests/BitSetTest.cpp',
+        '../tests/BitmapTest.cpp',
         '../tests/BlitRowTest.cpp',
         '../tests/BlurTest.cpp',
         '../tests/CachedDecodingPixelRefTest.cpp',
-        '../tests/CanvasTest.cpp',
         '../tests/CanvasStateTest.cpp',
+        '../tests/CanvasTest.cpp',
         '../tests/ChecksumTest.cpp',
         '../tests/ClampRangeTest.cpp',
         '../tests/ClipCacheTest.cpp',
@@ -74,9 +74,9 @@
         '../tests/FontMgrTest.cpp',
         '../tests/FontNamesTest.cpp',
         '../tests/FrontBufferedStreamTest.cpp',
-        '../tests/GeometryTest.cpp',
         '../tests/GLInterfaceValidation.cpp',
         '../tests/GLProgramsTest.cpp',
+        '../tests/GeometryTest.cpp',
         '../tests/GifTest.cpp',
         '../tests/GpuBitmapCopyTest.cpp',
         '../tests/GpuColorFilterTest.cpp',
         '../tests/MD5Test.cpp',
         '../tests/MallocPixelRefTest.cpp',
         '../tests/MathTest.cpp',
-        '../tests/MatrixTest.cpp',
         '../tests/Matrix44Test.cpp',
+        '../tests/MatrixTest.cpp',
         '../tests/MemoryTest.cpp',
         '../tests/MemsetTest.cpp',
         '../tests/MessageBusTest.cpp',
         '../tests/MetaDataTest.cpp',
         '../tests/MipMapTest.cpp',
-        '../tests/OnceTest.cpp',
         '../tests/OSPathTest.cpp',
+        '../tests/OnceTest.cpp',
+        '../tests/PDFPrimitivesTest.cpp',
         '../tests/PackBitsTest.cpp',
         '../tests/PaintTest.cpp',
         '../tests/ParsePathTest.cpp',
         '../tests/PathMeasureTest.cpp',
         '../tests/PathTest.cpp',
         '../tests/PathUtilsTest.cpp',
-        '../tests/PDFPrimitivesTest.cpp',
         '../tests/PictureTest.cpp',
         '../tests/PictureUtilsTest.cpp',
         '../tests/PipeTest.cpp',
         '../tests/PointTest.cpp',
         '../tests/PremulAlphaRoundTripTest.cpp',
         '../tests/QuickRejectTest.cpp',
+        '../tests/RTreeTest.cpp',
         '../tests/RandomTest.cpp',
-        '../tests/Reader32Test.cpp',
         '../tests/ReadPixelsTest.cpp',
         '../tests/ReadWriteAlphaTest.cpp',
+        '../tests/Reader32Test.cpp',
         '../tests/RefCntTest.cpp',
         '../tests/RefDictTest.cpp',
         '../tests/RegionTest.cpp',
         '../tests/ResourceCacheTest.cpp',
         '../tests/RoundRectTest.cpp',
         '../tests/RuntimeConfigTest.cpp',
-        '../tests/RTreeTest.cpp',
         '../tests/SHA1Test.cpp',
         '../tests/ScalarTest.cpp',
         '../tests/SerializationTest.cpp',
         '../tests/ShaderImageFilterTest.cpp',
         '../tests/ShaderOpacityTest.cpp',
-        '../tests/skia_test.cpp',
+        '../tests/SkBase64Test.cpp',
         '../tests/SortTest.cpp',
         '../tests/SrcOverTest.cpp',
         '../tests/StreamTest.cpp',
         '../tests/StringTest.cpp',
         '../tests/StrokeTest.cpp',
         '../tests/SurfaceTest.cpp',
+        '../tests/TLSTest.cpp',
+        '../tests/TSetTest.cpp',
         '../tests/Test.cpp',
         '../tests/Test.h',
         '../tests/TestSize.cpp',
         '../tests/TileGridTest.cpp',
-        '../tests/TLSTest.cpp',
-        '../tests/TSetTest.cpp',
         '../tests/ToUnicode.cpp',
         '../tests/Typeface.cpp',
         '../tests/UnicodeTest.cpp',
         '../tests/WritePixelsTest.cpp',
         '../tests/Writer32Test.cpp',
         '../tests/XfermodeTest.cpp',
+        '../tests/skia_test.cpp',
 
         '../experimental/PdfViewer/src/SkTDStackNester.h',
         '../tests/TDStackNesterTest.cpp',
index 11b647f..545a8eb 100644 (file)
@@ -162,24 +162,3 @@ SkBase64::Error SkBase64::decode(const char* src, size_t len) {
     decode(src, len, true);
     return kNoError;
 }
-
-#ifdef SK_SUPPORT_UNITTEST
-void SkBase64::UnitTest() {
-    signed char all[256];
-    for (int index = 0; index < 256; index++)
-        all[index] = (signed char) (index + 1);
-    for (int offset = 0; offset < 6; offset++) {
-        size_t length = 256 - offset;
-        size_t encodeLength = Encode(all + offset, length, NULL);
-        char* src = (char*)sk_malloc_throw(encodeLength + 1);
-        Encode(all + offset, length, src);
-        src[encodeLength] = '\0';
-        SkBase64 tryMe;
-        tryMe.decode(src, encodeLength);
-        SkASSERT(length == tryMe.fLength);
-        SkASSERT(strcmp((const char*) (all + offset), tryMe.fData) == 0);
-        sk_free(src);
-        delete[] tryMe.fData;
-    }
-}
-#endif
index 5bf9006..ba66dd2 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -6,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-
 #ifndef SkBase64_DEFINED
 #define SkBase64_DEFINED
 
@@ -30,9 +28,6 @@ public:
     */
     static size_t Encode(const void* src, size_t length, void* dest, const char* encode = NULL);
 
-#ifdef SK_SUPPORT_UNITTEST
-    static void UnitTest();
-#endif
 private:
     Error decode(const void* srcPtr, size_t length, bool writeDestination);
 
diff --git a/tests/SkBase64Test.cpp b/tests/SkBase64Test.cpp
new file mode 100644 (file)
index 0000000..aba9691
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBase64.h"
+
+#include "Test.h"
+
+DEF_TEST(SkBase64Test, reporter) {
+    char all[256];
+    for (int index = 0; index < 256; index++) {
+        all[index] = (signed char) (index + 1);
+    }
+
+    for (int offset = 0; offset < 6; offset++) {
+        size_t length = 256 - offset;
+        size_t encodeLength = SkBase64::Encode(all + offset, length, NULL);
+        SkAutoTMalloc<char> src(encodeLength + 1);
+        SkBase64::Encode(all + offset, length, src.get());
+        SkBase64 tryMe;
+        tryMe.decode(src.get(), encodeLength);
+        REPORTER_ASSERT(reporter, (strcmp((const char*) (all + offset), tryMe.getData()) == 0));
+        delete[] tryMe.getData();
+    }
+}