OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 RefPtr<SharedBuffer> sharedBuffer = | 56 RefPtr<SharedBuffer> sharedBuffer = |
57 SharedBuffer::create(testData, sizeof(testData)); | 57 SharedBuffer::create(testData, sizeof(testData)); |
58 | 58 |
59 SharedBufferReader reader(sharedBuffer); | 59 SharedBufferReader reader(sharedBuffer); |
60 | 60 |
61 const int extraBytes = 3; | 61 const int extraBytes = 3; |
62 char outputBuffer[sizeof(testData) + extraBytes]; | 62 char outputBuffer[sizeof(testData) + extraBytes]; |
63 | 63 |
64 const char initializationByte = 'a'; | 64 const char initializationByte = 'a'; |
65 memset(outputBuffer, initializationByte, sizeof(outputBuffer)); | 65 memset(outputBuffer, initializationByte, sizeof(outputBuffer)); |
66 EXPECT_EQ(sizeof(testData), static_cast<size_t>(reader.readData( | 66 EXPECT_EQ( |
67 outputBuffer, sizeof(outputBuffer)))); | 67 sizeof(testData), |
| 68 static_cast<size_t>(reader.readData(outputBuffer, sizeof(outputBuffer)))); |
68 | 69 |
69 EXPECT_TRUE(std::equal(testData, testData + sizeof(testData), outputBuffer)); | 70 EXPECT_TRUE(std::equal(testData, testData + sizeof(testData), outputBuffer)); |
70 // Check that the bytes past index sizeof(testData) were not touched. | 71 // Check that the bytes past index sizeof(testData) were not touched. |
71 EXPECT_EQ(extraBytes, | 72 EXPECT_EQ(extraBytes, |
72 std::count(outputBuffer, outputBuffer + sizeof(outputBuffer), | 73 std::count(outputBuffer, outputBuffer + sizeof(outputBuffer), |
73 initializationByte)); | 74 initializationByte)); |
74 } | 75 } |
75 | 76 |
76 TEST(SharedBufferReaderTest, readDataInMultiples) { | 77 TEST(SharedBufferReaderTest, readDataInMultiples) { |
77 const int iterationsCount = 8; | 78 const int iterationsCount = 8; |
(...skipping 30 matching lines...) Expand all Loading... |
108 Vector<char> destinationVector(testData.size()); | 109 Vector<char> destinationVector(testData.size()); |
109 const int bytesToRead = testData.size() / 2; | 110 const int bytesToRead = testData.size() / 2; |
110 EXPECT_EQ(bytesToRead, reader.readData(&destinationVector[0], bytesToRead)); | 111 EXPECT_EQ(bytesToRead, reader.readData(&destinationVector[0], bytesToRead)); |
111 | 112 |
112 sharedBuffer->clear(); | 113 sharedBuffer->clear(); |
113 | 114 |
114 EXPECT_EQ(0, reader.readData(&destinationVector[0], bytesToRead)); | 115 EXPECT_EQ(0, reader.readData(&destinationVector[0], bytesToRead)); |
115 } | 116 } |
116 | 117 |
117 } // namespace blink | 118 } // namespace blink |
OLD | NEW |