OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 SharedBuffer::create(testData0, strlen(testData0)); | 49 SharedBuffer::create(testData0, strlen(testData0)); |
50 sharedBuffer->append(testData1, strlen(testData1)); | 50 sharedBuffer->append(testData1, strlen(testData1)); |
51 sharedBuffer->append(testData2, strlen(testData2)); | 51 sharedBuffer->append(testData2, strlen(testData2)); |
52 | 52 |
53 const size_t size = sharedBuffer->size(); | 53 const size_t size = sharedBuffer->size(); |
54 std::unique_ptr<char[]> data = wrapArrayUnique(new char[size]); | 54 std::unique_ptr<char[]> data = wrapArrayUnique(new char[size]); |
55 sharedBuffer->getAsBytes(data.get(), size); | 55 sharedBuffer->getAsBytes(data.get(), size); |
56 | 56 |
57 char expectedConcatenation[] = "HelloWorldGoodbye"; | 57 char expectedConcatenation[] = "HelloWorldGoodbye"; |
58 ASSERT_EQ(strlen(expectedConcatenation), size); | 58 ASSERT_EQ(strlen(expectedConcatenation), size); |
59 EXPECT_EQ(0, memcmp(expectedConcatenation, data.get(), | 59 EXPECT_EQ( |
60 strlen(expectedConcatenation))); | 60 0, |
| 61 memcmp(expectedConcatenation, data.get(), strlen(expectedConcatenation))); |
61 } | 62 } |
62 | 63 |
63 TEST(SharedBufferTest, getPartAsBytes) { | 64 TEST(SharedBufferTest, getPartAsBytes) { |
64 char testData0[] = "Hello"; | 65 char testData0[] = "Hello"; |
65 char testData1[] = "World"; | 66 char testData1[] = "World"; |
66 char testData2[] = "Goodbye"; | 67 char testData2[] = "Goodbye"; |
67 | 68 |
68 RefPtr<SharedBuffer> sharedBuffer = | 69 RefPtr<SharedBuffer> sharedBuffer = |
69 SharedBuffer::create(testData0, strlen(testData0)); | 70 SharedBuffer::create(testData0, strlen(testData0)); |
70 sharedBuffer->append(testData1, strlen(testData1)); | 71 sharedBuffer->append(testData1, strlen(testData1)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(length); | 148 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(length); |
148 ASSERT_EQ(length, sharedBuffer->size()); | 149 ASSERT_EQ(length, sharedBuffer->size()); |
149 | 150 |
150 // The internal flat buffer should have been resized to |length| therefore | 151 // The internal flat buffer should have been resized to |length| therefore |
151 // getSomeData() should directly return the full size. | 152 // getSomeData() should directly return the full size. |
152 const char* data; | 153 const char* data; |
153 ASSERT_EQ(length, sharedBuffer->getSomeData(data, static_cast<size_t>(0u))); | 154 ASSERT_EQ(length, sharedBuffer->getSomeData(data, static_cast<size_t>(0u))); |
154 } | 155 } |
155 | 156 |
156 } // namespace blink | 157 } // namespace blink |
OLD | NEW |