OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 INRIA | 3 * Copyright (c) 2010 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 Ptr<UniformRandomVariable> bytesRng = CreateObject<UniformRandomVariable> ()
; | 287 Ptr<UniformRandomVariable> bytesRng = CreateObject<UniformRandomVariable> ()
; |
288 bytesRng->SetAttribute ("Min", DoubleValue (0)); | 288 bytesRng->SetAttribute ("Min", DoubleValue (0)); |
289 bytesRng->SetAttribute ("Max", DoubleValue (256)); | 289 bytesRng->SetAttribute ("Max", DoubleValue (256)); |
290 | 290 |
291 Buffer inputBuffer; | 291 Buffer inputBuffer; |
292 Buffer outputBuffer; | 292 Buffer outputBuffer; |
293 | 293 |
294 inputBuffer.AddAtEnd (actualSize); | 294 inputBuffer.AddAtEnd (actualSize); |
295 { | 295 { |
296 Buffer::Iterator iter = inputBuffer.Begin (); | 296 Buffer::Iterator iter = inputBuffer.Begin (); |
297 for (uint32_t i = 0; i < actualSize; i++) | 297 for (uint32_t j = 0; j < actualSize; j++) |
298 iter.WriteU8 (static_cast<uint8_t> (bytesRng->GetValue ())); | 298 iter.WriteU8 (static_cast<uint8_t> (bytesRng->GetValue ())); |
299 } | 299 } |
300 | 300 |
301 outputBuffer.AddAtEnd (chunkSize); | 301 outputBuffer.AddAtEnd (chunkSize); |
302 Buffer::Iterator iter = outputBuffer.End (); | 302 Buffer::Iterator iter = outputBuffer.End (); |
303 iter.Prev (chunkSize); | 303 iter.Prev (chunkSize); |
304 iter.Write (inputBuffer.PeekData (), chunkSize); | 304 iter.Write (inputBuffer.PeekData (), chunkSize); |
305 | 305 |
306 NS_TEST_EXPECT_MSG_EQ (memcmp (inputBuffer.PeekData (), outputBuffer.PeekDat
a (), chunkSize), 0, "memcp works"); | 306 NS_TEST_EXPECT_MSG_EQ (memcmp (inputBuffer.PeekData (), outputBuffer.PeekDat
a (), chunkSize), 0, "memcp works"); |
307 } | 307 } |
(...skipping 26 matching lines...) Expand all Loading... |
334 ENSURE_WRITTEN_BYTES (buffer, 9, 0x1, 0x2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3,
0x4); | 334 ENSURE_WRITTEN_BYTES (buffer, 9, 0x1, 0x2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3,
0x4); |
335 Buffer other; | 335 Buffer other; |
336 other.AddAtStart (9); | 336 other.AddAtStart (9); |
337 i = other.Begin (); | 337 i = other.Begin (); |
338 i.Write (buffer.Begin (), buffer.End ()); | 338 i.Write (buffer.Begin (), buffer.End ()); |
339 ENSURE_WRITTEN_BYTES (other, 9, 0x1, 0x2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3, 0
x4); | 339 ENSURE_WRITTEN_BYTES (other, 9, 0x1, 0x2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3, 0
x4); |
340 | 340 |
341 /// \internal See \bugid{1001} | 341 /// \internal See \bugid{1001} |
342 std::string ct ("This is the next content of the buffer."); | 342 std::string ct ("This is the next content of the buffer."); |
343 buffer = Buffer (); | 343 buffer = Buffer (); |
344 buffer.AddAtStart (ct.size ()); | 344 buffer.AddAtStart (static_cast<uint32_t> (ct.size ())); |
345 i = buffer.Begin (); | 345 i = buffer.Begin (); |
346 i.Write ((const uint8_t*)ct.c_str (), ct.size ()); | 346 i.Write ((const uint8_t*)ct.c_str (), static_cast<uint32_t> (ct.size ())); |
347 uint32_t sizeBuffer = buffer.GetSize (); | 347 uint32_t sizeBuffer = buffer.GetSize (); |
348 NS_TEST_ASSERT_MSG_EQ (sizeBuffer, ct.size(), "Buffer bad size"); | 348 NS_TEST_ASSERT_MSG_EQ (sizeBuffer, ct.size(), "Buffer bad size"); |
349 uint8_t const* evilBuffer = buffer.PeekData (); | 349 uint8_t const* evilBuffer = buffer.PeekData (); |
350 NS_TEST_ASSERT_MSG_NE( evilBuffer, 0, "Buffer PeekData failed"); | 350 NS_TEST_ASSERT_MSG_NE( evilBuffer, 0, "Buffer PeekData failed"); |
351 uint8_t *cBuf = (uint8_t*) malloc ( sizeBuffer ); | 351 uint8_t *cBuf = (uint8_t*) malloc ( sizeBuffer ); |
352 uint32_t copyLen = buffer.CopyData (cBuf, sizeBuffer); | 352 uint32_t copyLen = buffer.CopyData (cBuf, sizeBuffer); |
353 NS_TEST_ASSERT_MSG_EQ (copyLen, sizeBuffer, "CopyData return bad size"); | 353 NS_TEST_ASSERT_MSG_EQ (copyLen, sizeBuffer, "CopyData return bad size"); |
354 for (uint8_t i=0; i < sizeBuffer ; i++ ) | 354 for (uint8_t j=0; j < sizeBuffer ; j++ ) |
355 { | 355 { |
356 NS_TEST_ASSERT_MSG_EQ ( cBuf [i], *(((const uint8_t*)ct.c_str ()) + i), "B
ad buffer copied data"); | 356 NS_TEST_ASSERT_MSG_EQ ( cBuf [j], *(((const uint8_t*)ct.c_str ()) + j), "B
ad buffer copied data"); |
357 NS_TEST_ASSERT_MSG_EQ ( evilBuffer [i], cBuf [i] , "Bad buffer peeked"); | 357 NS_TEST_ASSERT_MSG_EQ ( evilBuffer [j], cBuf [j] , "Bad buffer peeked"); |
358 } | 358 } |
359 free (cBuf); | 359 free (cBuf); |
360 | 360 |
361 /// \internal See \bugid{2044} Will not pass without bug2044 fix. | 361 /// \internal See \bugid{2044} Will not pass without bug2044 fix. |
362 buffer = Buffer (1); | 362 buffer = Buffer (1); |
363 buffer.AddAtEnd (2); | 363 buffer.AddAtEnd (2); |
364 i = buffer.Begin (); | 364 i = buffer.Begin (); |
365 i.Next (1); | 365 i.Next (1); |
366 i.WriteU8 (0x77); | 366 i.WriteU8 (0x77); |
367 i.WriteU8 (0x66); | 367 i.WriteU8 (0x66); |
(...skipping 22 matching lines...) Expand all Loading... |
390 BufferTestSuite (); | 390 BufferTestSuite (); |
391 }; | 391 }; |
392 | 392 |
393 BufferTestSuite::BufferTestSuite () | 393 BufferTestSuite::BufferTestSuite () |
394 : TestSuite ("buffer", UNIT) | 394 : TestSuite ("buffer", UNIT) |
395 { | 395 { |
396 AddTestCase (new BufferTest, TestCase::QUICK); | 396 AddTestCase (new BufferTest, TestCase::QUICK); |
397 } | 397 } |
398 | 398 |
399 static BufferTestSuite g_bufferTestSuite; //!< Static variable for test initiali
zation | 399 static BufferTestSuite g_bufferTestSuite; //!< Static variable for test initiali
zation |
OLD | NEW |