| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 char testData1[] = "World"; | 45 char testData1[] = "World"; |
| 46 char testData2[] = "Goodbye"; | 46 char testData2[] = "Goodbye"; |
| 47 | 47 |
| 48 RefPtr<SharedBuffer> sharedBuffer = | 48 RefPtr<SharedBuffer> sharedBuffer = |
| 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 ASSERT_TRUE(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(0, memcmp(expectedConcatenation, data.get(), |
| 60 strlen(expectedConcatenation))); | 60 strlen(expectedConcatenation))); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST(SharedBufferTest, getPartAsBytes) { | 63 TEST(SharedBufferTest, getPartAsBytes) { |
| 64 char testData0[] = "Hello"; | 64 char testData0[] = "Hello"; |
| 65 char testData1[] = "World"; | 65 char testData1[] = "World"; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 95 Vector<char> vector2(0x4000); | 95 Vector<char> vector2(0x4000); |
| 96 for (size_t i = 0; i < vector2.size(); ++i) | 96 for (size_t i = 0; i < vector2.size(); ++i) |
| 97 vector2[i] = 'c'; | 97 vector2[i] = 'c'; |
| 98 | 98 |
| 99 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::adoptVector(vector0); | 99 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::adoptVector(vector0); |
| 100 sharedBuffer->append(vector1); | 100 sharedBuffer->append(vector1); |
| 101 sharedBuffer->append(vector2); | 101 sharedBuffer->append(vector2); |
| 102 | 102 |
| 103 const size_t size = sharedBuffer->size(); | 103 const size_t size = sharedBuffer->size(); |
| 104 std::unique_ptr<char[]> data = wrapArrayUnique(new char[size]); | 104 std::unique_ptr<char[]> data = wrapArrayUnique(new char[size]); |
| 105 ASSERT_TRUE(sharedBuffer->getAsBytes(data.get(), size)); | 105 sharedBuffer->getAsBytes(data.get(), size); |
| 106 | 106 |
| 107 ASSERT_EQ(0x4000U + 0x4000U + 0x4000U, size); | 107 ASSERT_EQ(0x4000U + 0x4000U + 0x4000U, size); |
| 108 int position = 0; | 108 int position = 0; |
| 109 for (int i = 0; i < 0x4000; ++i) { | 109 for (int i = 0; i < 0x4000; ++i) { |
| 110 EXPECT_EQ('a', data[position]); | 110 EXPECT_EQ('a', data[position]); |
| 111 ++position; | 111 ++position; |
| 112 } | 112 } |
| 113 for (int i = 0; i < 0x4000; ++i) { | 113 for (int i = 0; i < 0x4000; ++i) { |
| 114 EXPECT_EQ('b', data[position]); | 114 EXPECT_EQ('b', data[position]); |
| 115 ++position; | 115 ++position; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(length); | 147 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(length); |
| 148 ASSERT_EQ(length, sharedBuffer->size()); | 148 ASSERT_EQ(length, sharedBuffer->size()); |
| 149 | 149 |
| 150 // The internal flat buffer should have been resized to |length| therefore | 150 // The internal flat buffer should have been resized to |length| therefore |
| 151 // getSomeData() should directly return the full size. | 151 // getSomeData() should directly return the full size. |
| 152 const char* data; | 152 const char* data; |
| 153 ASSERT_EQ(length, sharedBuffer->getSomeData(data, static_cast<size_t>(0u))); | 153 ASSERT_EQ(length, sharedBuffer->getSomeData(data, static_cast<size_t>(0u))); |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace blink | 156 } // namespace blink |
| OLD | NEW |