Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: third_party/WebKit/Source/platform/SharedBufferTest.cpp

Issue 2249533003: [Platform] Enable to get a partial data of SharedBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/SharedBuffer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ASSERT_TRUE(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(), strlen(expectedConcat enation))); 59 EXPECT_EQ(0, memcmp(expectedConcatenation, data.get(), strlen(expectedConcat enation)));
60 } 60 }
61 61
62 TEST(SharedBufferTest, getPartAsBytes)
63 {
64 char testData0[] = "Hello";
65 char testData1[] = "World";
66 char testData2[] = "Goodbye";
67
68 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(testData0, strlen(t estData0));
69 sharedBuffer->append(testData1, strlen(testData1));
70 sharedBuffer->append(testData2, strlen(testData2));
71
72 struct TestData {
73 size_t position;
74 size_t size;
75 const char* expected;
76 } testData[] = {
77 {0, 17, "HelloWorldGoodbye"},
78 {0, 7, "HelloWo"},
79 {4, 7, "oWorldG"},
80 };
81 for (TestData& test : testData) {
82 std::unique_ptr<char[]> data = wrapArrayUnique(new char[test.size]);
83 ASSERT_TRUE(sharedBuffer->getPartAsBytes(data.get(), test.position, test .size));
84 EXPECT_EQ(0, memcmp(test.expected, data.get(), test.size));
85 }
86 }
87
62 TEST(SharedBufferTest, getAsBytesLargeSegments) 88 TEST(SharedBufferTest, getAsBytesLargeSegments)
63 { 89 {
64 Vector<char> vector0(0x4000); 90 Vector<char> vector0(0x4000);
65 for (size_t i = 0; i < vector0.size(); ++i) 91 for (size_t i = 0; i < vector0.size(); ++i)
66 vector0[i] = 'a'; 92 vector0[i] = 'a';
67 Vector<char> vector1(0x4000); 93 Vector<char> vector1(0x4000);
68 for (size_t i = 0; i < vector1.size(); ++i) 94 for (size_t i = 0; i < vector1.size(); ++i)
69 vector1[i] = 'b'; 95 vector1[i] = 'b';
70 Vector<char> vector2(0x4000); 96 Vector<char> vector2(0x4000);
71 for (size_t i = 0; i < vector2.size(); ++i) 97 for (size_t i = 0; i < vector2.size(); ++i)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 168
143 // Do another append + merge the segments again. 169 // Do another append + merge the segments again.
144 size_t previousTestDataSize = testData.size(); 170 size_t previousTestDataSize = testData.size();
145 testData.resize(2 * previousTestDataSize); 171 testData.resize(2 * previousTestDataSize);
146 std::generate(testData.begin() + previousTestDataSize, testData.end(), &std: :rand); 172 std::generate(testData.begin() + previousTestDataSize, testData.end(), &std: :rand);
147 sharedBuffer->append(testData.data() + previousTestDataSize, previousTestDat aSize); 173 sharedBuffer->append(testData.data() + previousTestDataSize, previousTestDat aSize);
148 ASSERT_EQ(0, memcmp(data, testData.data(), length)); 174 ASSERT_EQ(0, memcmp(data, testData.data(), length));
149 } 175 }
150 176
151 } // namespace blink 177 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/SharedBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698