summaryrefslogtreecommitdiff
path: root/src/test/VariantTest.cpp
diff options
context:
space:
mode:
authorJohannes Schanda <schanda@itestra.de>2013-05-29 23:13:34 +0200
committerJohannes Schanda <schanda@itestra.de>2013-05-29 23:13:34 +0200
commitbe635b51f6ad0b978a3aa8f7e1a167495b9f3b70 (patch)
treebbe1f0c4642942080e41a12209a3a50855c7b4b1 /src/test/VariantTest.cpp
parent447790b568b7d2710ae10ddeb16d57b19561757e (diff)
downloadgenivi-common-api-runtime-be635b51f6ad0b978a3aa8f7e1a167495b9f3b70.tar.gz
Corrected move constructor / initialisation of empty variant
Diffstat (limited to 'src/test/VariantTest.cpp')
-rwxr-xr-xsrc/test/VariantTest.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/test/VariantTest.cpp b/src/test/VariantTest.cpp
index 441a288..4d7e5e1 100755
--- a/src/test/VariantTest.cpp
+++ b/src/test/VariantTest.cpp
@@ -15,6 +15,52 @@ class VariantTest: public ::testing::Test {
}
};
+
+struct test1: CommonAPI::SerializableStruct {
+ int a;
+ std::string b;
+
+ test1() = default;
+ test1(const int& a, const std::string& b) :
+ a(a), b(b) {
+ }
+
+ void readFromInputStream(CommonAPI::InputStream& inputStream) {
+
+ }
+
+ void writeToOutputStream(CommonAPI::OutputStream& outputStream) const {
+
+ }
+
+ static inline void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) {
+ }
+
+};
+
+struct test2: CommonAPI::SerializableStruct {
+ int a;
+ std::string b;
+
+ test2() = default;
+ test2(const int& a, const std::string& b) :
+ a(a), b(b) {
+ }
+
+ void readFromInputStream(CommonAPI::InputStream& inputStream) {
+
+ }
+
+ void writeToOutputStream(CommonAPI::OutputStream& outputStream) const {
+
+ }
+
+ static inline void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) {
+ }
+
+};
+
+
TEST_F(VariantTest, VariantTestPack) {
int fromInt = 5;
@@ -70,6 +116,11 @@ TEST_F(VariantTest, VariantTestPack) {
std::cout << "myInt is std::string = " << "\n";
EXPECT_FALSE(myVariant.isType<std::string>());
+ Variant<int, double, std::string> movedVariant = std::move(myVariant);
+ std::cout << "myMovedInt is int = " << " (" << std::boolalpha << movedVariant.isType<int>() << ")\n";
+ EXPECT_TRUE(movedVariant.isType<int>());
+ EXPECT_EQ(fromInt, movedVariant.get<int>());
+
const double& myDouble = myVariantf.get<double>();
std::cout << "myDouble = " << myDouble << "\n";
@@ -85,6 +136,14 @@ TEST_F(VariantTest, VariantTestPack) {
std::cout << "myStringCopy = " << myStringCopy << "\n";
delete myVariants;
+
+ test1 sourceStruct = {1, "a"};
+
+ Variant<test1, test2> complexSource = sourceStruct;
+
+ Variant<test1, test2> complexTarget = complexSource;
+ EXPECT_EQ(1, complexTarget.get<test1>().a);
+
}
int main(int argc, char** argv) {