FixedSizeBitsetTests.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzNetworking/DataStructures/FixedSizeBitset.h>
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. namespace UnitTest
  11. {
  12. TEST(FixedSizeBitset, TestSetBit)
  13. {
  14. AzNetworking::FixedSizeBitset<128> test;
  15. test.SetBit(0, true);
  16. test.SetBit(2, true);
  17. // 0000 0101
  18. EXPECT_EQ(test.GetContainer()[0], 0x05);
  19. }
  20. TEST(FixedSizeBitset, TestAppend)
  21. {
  22. AzNetworking::FixedSizeBitset<63> appendTest1;
  23. appendTest1.SetBit(1, true);
  24. AzNetworking::FixedSizeBitset<63> appendTest2;
  25. appendTest2.SetBit(2, true);
  26. appendTest2.SetBit(32, true);
  27. appendTest1 |= appendTest2;
  28. EXPECT_EQ(appendTest1.GetBit(1), true);
  29. EXPECT_EQ(appendTest1.GetBit(2), true);
  30. EXPECT_EQ(appendTest1.GetBit(32), true);
  31. }
  32. TEST(FixedSizeBitset, TestAllSet)
  33. {
  34. AzNetworking::FixedSizeBitset<63> unusedBitTest(true);
  35. bool allSet = true;
  36. for (uint32_t i = 0; i < 63; ++i)
  37. {
  38. allSet &= unusedBitTest.GetBit(i);
  39. }
  40. EXPECT_EQ(allSet, true);
  41. }
  42. TEST(FixedSizeBitset, TestAnySet)
  43. {
  44. AzNetworking::FixedSizeBitset<9> unusedBitTest(true);
  45. for (uint32_t i = 0; i < 9; ++i)
  46. {
  47. unusedBitTest.SetBit(i, false);
  48. }
  49. EXPECT_FALSE(unusedBitTest.AnySet());
  50. unusedBitTest.SetBit(0, true);
  51. EXPECT_TRUE(unusedBitTest.AnySet());
  52. }
  53. }