|
|
@@ -0,0 +1,68 @@
|
|
|
+//
|
|
|
+// opaque_typedef_arithmatic_test.cpp
|
|
|
+// opaque_typedef_test
|
|
|
+//
|
|
|
+// Created by Sam Jaffe on 8/8/20.
|
|
|
+// Copyright © 2020 Sam Jaffe. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#include <gmock/gmock.h>
|
|
|
+#include <cmath>
|
|
|
+
|
|
|
+#include "opaque_typedef/arithmatic.hpp"
|
|
|
+#include "opaque_typedef/opaque_typedef.hpp"
|
|
|
+
|
|
|
+// Allow Eq() checks without needing the Skill EqualityComparable
|
|
|
+template <typename T>
|
|
|
+bool operator==(T const & lhs, T const & rhs) {
|
|
|
+ return lhs.get() == rhs.get();
|
|
|
+}
|
|
|
+
|
|
|
+// Make compilation (but not linking) possible for StaticAssertTypeEq to check
|
|
|
+// 'does a real version of this function exist'
|
|
|
+template <typename T> void operator++(T, int);
|
|
|
+template <typename T> void operator++(T);
|
|
|
+template <typename T> void operator--(T, int);
|
|
|
+template <typename T> void operator--(T);
|
|
|
+
|
|
|
+// Types for Test Cases
|
|
|
+using namespace types;
|
|
|
+using counter = opaque_typedef<uint32_t, struct counter_tag, Incrementable>;
|
|
|
+using countdown = opaque_typedef<uint32_t, struct countdown_tag, Decrementable>;
|
|
|
+
|
|
|
+// Actual Test Bodies
|
|
|
+TEST(OpaqueTypedefDecrementableTest, CannotDecrement) {
|
|
|
+ counter c{1};
|
|
|
+ EXPECT_TRUE((testing::StaticAssertTypeEq<void, decltype(c--)>()));
|
|
|
+ EXPECT_TRUE((testing::StaticAssertTypeEq<void, decltype(--c)>()));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(OpaqueTypedefIncrementableTest, CanPostIncrement) {
|
|
|
+ counter c{1};
|
|
|
+ EXPECT_THAT(c++, testing::Eq(counter{1}));
|
|
|
+ EXPECT_THAT(c, testing::Eq(counter{2}));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(OpaqueTypedefIncrementableTest, CanPreIncrement) {
|
|
|
+ counter c{1};
|
|
|
+ EXPECT_THAT(++c, testing::Eq(counter{2}));
|
|
|
+ EXPECT_THAT(c, testing::Eq(counter{2}));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(OpaqueTypedefDecrementableTest, CannotIncrement) {
|
|
|
+ countdown c{10};
|
|
|
+ EXPECT_TRUE((testing::StaticAssertTypeEq<void, decltype(c++)>()));
|
|
|
+ EXPECT_TRUE((testing::StaticAssertTypeEq<void, decltype(++c)>()));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(OpaqueTypedefDecrementableTest, CanPostDecrement) {
|
|
|
+ countdown c{10};
|
|
|
+ EXPECT_THAT(c--, testing::Eq(countdown{10}));
|
|
|
+ EXPECT_THAT(c, testing::Eq(countdown{9}));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(OpaqueTypedefDecrementableTest, CanPreDecrement) {
|
|
|
+ countdown c{10};
|
|
|
+ EXPECT_THAT(--c, testing::Eq(countdown{9}));
|
|
|
+ EXPECT_THAT(c, testing::Eq(countdown{9}));
|
|
|
+}
|