OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | 8 #include "Test.h" |
10 | 9 #include "TestClassDef.h" |
11 #include "SkReader32.h" | 10 #include "SkReader32.h" |
12 #include "Test.h" | |
13 | 11 |
14 static void assert_eof(skiatest::Reporter* reporter, const SkReader32& reader) { | 12 static void assert_eof(skiatest::Reporter* reporter, const SkReader32& reader) { |
15 REPORTER_ASSERT(reporter, reader.eof()); | 13 REPORTER_ASSERT(reporter, reader.eof()); |
16 REPORTER_ASSERT(reporter, reader.size() == reader.offset()); | 14 REPORTER_ASSERT(reporter, reader.size() == reader.offset()); |
17 REPORTER_ASSERT(reporter, (const char*)reader.peek() == | 15 REPORTER_ASSERT(reporter, (const char*)reader.peek() == |
18 (const char*)reader.base() + reader.size()); | 16 (const char*)reader.base() + reader.size()); |
19 } | 17 } |
20 | 18 |
21 static void assert_start(skiatest::Reporter* reporter, const SkReader32& reader)
{ | 19 static void assert_start(skiatest::Reporter* reporter, const SkReader32& reader)
{ |
22 REPORTER_ASSERT(reporter, 0 == reader.offset()); | 20 REPORTER_ASSERT(reporter, 0 == reader.offset()); |
23 REPORTER_ASSERT(reporter, reader.size() == reader.available()); | 21 REPORTER_ASSERT(reporter, reader.size() == reader.available()); |
24 REPORTER_ASSERT(reporter, reader.isAvailable(reader.size())); | 22 REPORTER_ASSERT(reporter, reader.isAvailable(reader.size())); |
25 REPORTER_ASSERT(reporter, !reader.isAvailable(reader.size() + 1)); | 23 REPORTER_ASSERT(reporter, !reader.isAvailable(reader.size() + 1)); |
26 REPORTER_ASSERT(reporter, reader.peek() == reader.base()); | 24 REPORTER_ASSERT(reporter, reader.peek() == reader.base()); |
27 } | 25 } |
28 | 26 |
29 static void assert_empty(skiatest::Reporter* reporter, const SkReader32& reader)
{ | 27 static void assert_empty(skiatest::Reporter* reporter, const SkReader32& reader)
{ |
30 REPORTER_ASSERT(reporter, 0 == reader.size()); | 28 REPORTER_ASSERT(reporter, 0 == reader.size()); |
31 REPORTER_ASSERT(reporter, 0 == reader.offset()); | 29 REPORTER_ASSERT(reporter, 0 == reader.offset()); |
32 REPORTER_ASSERT(reporter, 0 == reader.available()); | 30 REPORTER_ASSERT(reporter, 0 == reader.available()); |
33 REPORTER_ASSERT(reporter, !reader.isAvailable(1)); | 31 REPORTER_ASSERT(reporter, !reader.isAvailable(1)); |
34 assert_eof(reporter, reader); | 32 assert_eof(reporter, reader); |
35 assert_start(reporter, reader); | 33 assert_start(reporter, reader); |
36 } | 34 } |
37 | 35 |
38 static void Tests(skiatest::Reporter* reporter) { | 36 DEF_TEST(Reader32, reporter) { |
39 SkReader32 reader; | 37 SkReader32 reader; |
40 assert_empty(reporter, reader); | 38 assert_empty(reporter, reader); |
41 REPORTER_ASSERT(reporter, NULL == reader.base()); | 39 REPORTER_ASSERT(reporter, NULL == reader.base()); |
42 REPORTER_ASSERT(reporter, NULL == reader.peek()); | 40 REPORTER_ASSERT(reporter, NULL == reader.peek()); |
43 | 41 |
44 size_t i; | 42 size_t i; |
45 | 43 |
46 const int32_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | 44 const int32_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; |
47 const SkScalar data2[] = { 0, SK_Scalar1, -SK_Scalar1, SK_Scalar1/2 }; | 45 const SkScalar data2[] = { 0, SK_Scalar1, -SK_Scalar1, SK_Scalar1/2 }; |
48 const size_t bufsize = sizeof(data) > sizeof(data2) ? | 46 const size_t bufsize = sizeof(data) > sizeof(data2) ? |
(...skipping 26 matching lines...) Expand all Loading... |
75 reader.rewind(); | 73 reader.rewind(); |
76 assert_start(reporter, reader); | 74 assert_start(reporter, reader); |
77 reader.read(buffer, sizeof(data2)); | 75 reader.read(buffer, sizeof(data2)); |
78 REPORTER_ASSERT(reporter, !memcmp(data2, buffer, sizeof(data2))); | 76 REPORTER_ASSERT(reporter, !memcmp(data2, buffer, sizeof(data2))); |
79 | 77 |
80 reader.setMemory(NULL, 0); | 78 reader.setMemory(NULL, 0); |
81 assert_empty(reporter, reader); | 79 assert_empty(reporter, reader); |
82 REPORTER_ASSERT(reporter, NULL == reader.base()); | 80 REPORTER_ASSERT(reporter, NULL == reader.base()); |
83 REPORTER_ASSERT(reporter, NULL == reader.peek()); | 81 REPORTER_ASSERT(reporter, NULL == reader.peek()); |
84 } | 82 } |
85 | |
86 #include "TestClassDef.h" | |
87 DEFINE_TESTCLASS("Reader32", Reader32Class, Tests) | |
OLD | NEW |