Skip to content

Commit

Permalink
Add mutex_protected_test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaski committed Jan 15, 2025
1 parent 92f34ff commit ab73eda
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ endmacro(add_test_file)

add_test_file(src/utilities_test.cpp false)
add_test_file(src/concurrentrun_test.cpp false)
add_test_file(src/mutex_protected_test.cpp false)
add_test_file(src/mergedproxymodel_test.cpp false)
add_test_file(src/sqlite_test.cpp false)
add_test_file(src/tagreader_test.cpp false)
Expand Down
85 changes: 85 additions & 0 deletions tests/src/mutex_protected_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <gtest/gtest.h>

#include "includes/mutex_protected.h"

TEST(MutexProtectedTest, Test1) {

mutex_protected<int> value1 = 0;
mutex_protected<int> value2 = 0;

EXPECT_EQ(value1, 0);
EXPECT_EQ(value2, 0);
EXPECT_EQ(value1, value2);
EXPECT_TRUE(value1 == value2);
EXPECT_FALSE(value1 != value2);
EXPECT_FALSE(value1 > value2);
EXPECT_FALSE(value1 < value2);
EXPECT_TRUE(value1 >= value2);
EXPECT_TRUE(value1 <= value2);

++value2;

EXPECT_EQ(value1, 0);
EXPECT_EQ(value2, 1);
EXPECT_LE(value1, value2);
EXPECT_FALSE(value1 == value2);
EXPECT_TRUE(value1 != value2);
EXPECT_FALSE(value1 > value2);
EXPECT_TRUE(value1 < value2);
EXPECT_FALSE(value1 >= value2);
EXPECT_TRUE(value1 <= value2);

value1 += 5;

EXPECT_EQ(value1, 5);
EXPECT_EQ(value2, 1);
EXPECT_GT(value1, value2);
EXPECT_FALSE(value1 == value2);
EXPECT_TRUE(value1 != value2);
EXPECT_TRUE(value1 > value2);
EXPECT_FALSE(value1 < value2);
EXPECT_TRUE(value1 >= value2);
EXPECT_FALSE(value1 <= value2);

}

TEST(MutexProtectedTest, Test2) {

mutex_protected<int> value1 = 0;
int value2 = 0;

EXPECT_EQ(value1, 0);
EXPECT_EQ(value2, 0);
EXPECT_EQ(value1, value2);
EXPECT_TRUE(value1 == value2);
EXPECT_FALSE(value1 != value2);
EXPECT_FALSE(value1 > value2);
EXPECT_FALSE(value1 < value2);
EXPECT_TRUE(value1 >= value2);
EXPECT_TRUE(value1 <= value2);

++value2;

EXPECT_EQ(value1, 0);
EXPECT_EQ(value2, 1);
EXPECT_LE(value1, value2);
EXPECT_FALSE(value1 == value2);
EXPECT_TRUE(value1 != value2);
EXPECT_FALSE(value1 > value2);
EXPECT_TRUE(value1 < value2);
EXPECT_FALSE(value1 >= value2);
EXPECT_TRUE(value1 <= value2);

value1 += 5;

EXPECT_EQ(value1, 5);
EXPECT_EQ(value2, 1);
EXPECT_GT(value1, value2);
EXPECT_FALSE(value1 == value2);
EXPECT_TRUE(value1 != value2);
EXPECT_TRUE(value1 > value2);
EXPECT_FALSE(value1 < value2);
EXPECT_TRUE(value1 >= value2);
EXPECT_FALSE(value1 <= value2);

}

0 comments on commit ab73eda

Please sign in to comment.