From e33a54d172e27194a24c9ba501851bf917849f03 Mon Sep 17 00:00:00 2001 From: Philip Rauwolf Date: Tue, 15 Jan 2013 15:23:49 +0100 Subject: [PATCH] Finalized tests --- src/test/DBusTypeStreamTest.cpp | 188 +++++++++++++++++++++++++--------------- 1 file changed, 120 insertions(+), 68 deletions(-) diff --git a/src/test/DBusTypeStreamTest.cpp b/src/test/DBusTypeStreamTest.cpp index d1ad75a..25bc82f 100644 --- a/src/test/DBusTypeStreamTest.cpp +++ b/src/test/DBusTypeStreamTest.cpp @@ -17,11 +17,30 @@ #include +struct TestStruct: public CommonAPI::SerializableStruct { + TestStruct(): uint16Val_(42), stringVal_("Hai!"), variantVal_(13.37) { + } + + virtual ~TestStruct() {} + + virtual void readFromInputStream(CommonAPI::InputStream& inputStream) { + } + virtual void writeToOutputStream(CommonAPI::OutputStream& outputStream) const { + } -//############################################################################################################## + static void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) { + CommonAPI::TypeWriter::writeType(typeOutputStream); + CommonAPI::TypeWriter::writeType(typeOutputStream); + CommonAPI::TypeWriter>>::writeType(typeOutputStream); + } + private: + uint16_t uint16Val_; + std::string stringVal_; + CommonAPI::Variant> variantVal_; +}; class TypeOutputStreamTest: public ::testing::Test { @@ -32,157 +51,190 @@ class TypeOutputStreamTest: public ::testing::Test { void TearDown() { } + + CommonAPI::DBus::DBusTypeOutputStream typeStream_; }; -TEST_F(TypeOutputStreamTest, CreatesBoolSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); +TEST_F(TypeOutputStreamTest, CreatesBasicTypeSignatures) { + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("b") == 0); } TEST_F(TypeOutputStreamTest, CreatesInt8Signature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("y") == 0); } TEST_F(TypeOutputStreamTest, CreatesInt16Signature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("n") == 0); } TEST_F(TypeOutputStreamTest, CreatesInt32Signature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("i") == 0); } TEST_F(TypeOutputStreamTest, CreatesInt64Signature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("x") == 0); } TEST_F(TypeOutputStreamTest, CreatesUInt8Signature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("y") == 0); } TEST_F(TypeOutputStreamTest, CreatesUInt16Signature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("q") == 0); } TEST_F(TypeOutputStreamTest, CreatesUInt32Signature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("u") == 0); } TEST_F(TypeOutputStreamTest, CreatesUInt64Signature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("t") == 0); } TEST_F(TypeOutputStreamTest, CreatesFloatSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("d") == 0); } TEST_F(TypeOutputStreamTest, CreatesDoubleSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("d") == 0); } TEST_F(TypeOutputStreamTest, CreatesStringSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("s") == 0); } TEST_F(TypeOutputStreamTest, CreatesByteBufferSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("ay") == 0); } TEST_F(TypeOutputStreamTest, CreatesVersionSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("(uu)") == 0); } TEST_F(TypeOutputStreamTest, CreatesVariantWithBasicTypesSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter>::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter>::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("v") == 0); } TEST_F(TypeOutputStreamTest, CreatesVariantWithVariantSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter, CommonAPI::Variant, std::string>, std::string>>::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter, CommonAPI::Variant, std::string>, std::string>>::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("v") == 0); } TEST_F(TypeOutputStreamTest, CreatesVectorOfStringsSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter >::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter >::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("as") == 0); } TEST_F(TypeOutputStreamTest, CreatesVectorOfVersionsSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter >::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter >::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("a(uu)") == 0); } TEST_F(TypeOutputStreamTest, CreatesVectorOfVariantsSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter> >::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter> >::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("av") == 0); } TEST_F(TypeOutputStreamTest, CreatesVectorOfVectorOfStringsSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter> >::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter> >::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("aas") == 0); } TEST_F(TypeOutputStreamTest, CreatesMapOfUInt16ToStringSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter>::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter>::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("a{qs}") == 0); } TEST_F(TypeOutputStreamTest, CreatesVectorOfMapsOfUInt16ToStringSignature) { - CommonAPI::DBus::DBusTypeOutputStream typeStream; - CommonAPI::TypeWriter> >::writeType(typeStream); - std::string signature = typeStream.retrieveSignature(); + CommonAPI::TypeWriter> >::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); ASSERT_TRUE(signature.compare("aa{qs}") == 0); } +TEST_F(TypeOutputStreamTest, ParsesSignatureOfTestStructCorrectly) { + CommonAPI::TypeWriter::writeType(typeStream_); + std::string signature = typeStream_.retrieveSignature(); + ASSERT_TRUE(signature.compare("(qsv)") == 0); +} + + +TEST_F(TypeOutputStreamTest, ParsesSignatureOfUInt32TypeVariantsCorrectly) { + uint32_t fromUInt = 42; + CommonAPI::Variant myVariant(fromUInt); + + CommonAPI::TypeSearchVisitor searchVisitor(typeStream_); + CommonAPI::ApplyVoidVisitor, uint32_t, double, std::string>::visit(searchVisitor, myVariant); + + std::string signature = typeStream_.retrieveSignature(); + ASSERT_TRUE(signature.compare("u") == 0); +} + + +TEST_F(TypeOutputStreamTest, ParsesSignatureOfStringTypeVariantsCorrectly) { + std::string fromString = "Hai!"; + CommonAPI::Variant myVariant(fromString); + + CommonAPI::TypeSearchVisitor searchVisitor(typeStream_); + CommonAPI::ApplyVoidVisitor, uint32_t, double, std::string>::visit(searchVisitor, myVariant); + + std::string signature = typeStream_.retrieveSignature(); + ASSERT_TRUE(signature.compare("s") == 0); +} + + +TEST_F(TypeOutputStreamTest, ParsesSignatureOfVectorTypeVariantsCorrectly) { + std::vector fromStringVector; + CommonAPI::Variant> myVariant(fromStringVector); + + CommonAPI::TypeSearchVisitor searchVisitor(typeStream_); + CommonAPI::ApplyVoidVisitor>, uint32_t, double, std::vector>::visit(searchVisitor, myVariant); + + std::string signature = typeStream_.retrieveSignature(); + ASSERT_TRUE(signature.compare("as") == 0); +} + + +TEST_F(TypeOutputStreamTest, ParsesSignatureOfTestStructTypeVariantsCorrectly) { + TestStruct fromTestStruct; + CommonAPI::Variant myVariant(fromTestStruct); + + CommonAPI::TypeSearchVisitor searchVisitor(typeStream_); + CommonAPI::ApplyVoidVisitor, uint32_t, double, TestStruct>::visit(searchVisitor, myVariant); + + std::string signature = typeStream_.retrieveSignature(); + ASSERT_TRUE(signature.compare("(qsv)") == 0); +} -- 2.7.4