/ src / common / UnitTests-CommonUtils / MsWindowsSettings.Tests.cpp
MsWindowsSettings.Tests.cpp
 1  #include "pch.h"
 2  #include "TestHelpers.h"
 3  #include <MsWindowsSettings.h>
 4  
 5  using namespace Microsoft::VisualStudio::CppUnitTestFramework;
 6  
 7  namespace UnitTestsCommonUtils
 8  {
 9      TEST_CLASS(MsWindowsSettingsTests)
10      {
11      public:
12          TEST_METHOD(GetAnimationsEnabled_ReturnsBoolean)
13          {
14              bool result = GetAnimationsEnabled();
15  
16              // Should return a valid boolean
17              Assert::IsTrue(result == true || result == false);
18          }
19  
20          TEST_METHOD(GetAnimationsEnabled_ConsistentResults)
21          {
22              // Multiple calls should return consistent results
23              bool result1 = GetAnimationsEnabled();
24              bool result2 = GetAnimationsEnabled();
25              bool result3 = GetAnimationsEnabled();
26  
27              Assert::AreEqual(result1, result2);
28              Assert::AreEqual(result2, result3);
29          }
30  
31          TEST_METHOD(GetAnimationsEnabled_DoesNotCrash)
32          {
33              // Call multiple times to ensure stability
34              for (int i = 0; i < 100; ++i)
35              {
36                  GetAnimationsEnabled();
37              }
38              Assert::IsTrue(true);
39          }
40  
41          TEST_METHOD(GetAnimationsEnabled_ThreadSafe)
42          {
43              std::vector<std::thread> threads;
44              std::atomic<int> successCount{ 0 };
45  
46              for (int i = 0; i < 10; ++i)
47              {
48                  threads.emplace_back([&successCount]() {
49                      for (int j = 0; j < 10; ++j)
50                      {
51                          GetAnimationsEnabled();
52                          successCount++;
53                      }
54                  });
55              }
56  
57              for (auto& t : threads)
58              {
59                  t.join();
60              }
61  
62              Assert::AreEqual(100, successCount.load());
63          }
64      };
65  }