CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
ADD_SUBDIRECTORY(idlc)
+ADD_SUBDIRECTORY(unit_tests)
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
Source1001: %{name}.manifest
+Source1002: %{name}-tests.manifest
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
BuildRequires: cmake
BuildRequires: flex
BuildRequires: bison
+BuildRequires: gtest-devel
%description
Tizen Interface Definition Language
+%package tests
+Summary: Unit tests for TIDL
+Requires: %{name} = %{version}
+
+%description tests
+Unit tests for TIDL
+
%prep
%setup -q
cp %{SOURCE1001} .
+cp %{SOURCE1002} .
%build
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
%manifest %{name}.manifest
%{_bindir}/tidlc
+%files tests
+%manifest %{name}.manifest
+%{_bindir}/*
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(TIDL_UNIT_TESTS CXX)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wno-unused-function -Wno-sign-compare")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" )
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -std=c++11")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+
+FIND_PACKAGE(GTest REQUIRED)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
+INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS})
+
+SET(TIDLC_SOURCES
+ ../idlc/document.cc
+ ../idlc/declaration.cc
+ ../idlc/interface.cc
+ ../idlc/type.cc
+ ../idlc/parameter.cc
+ ../idlc/attribute.cc
+ ../idlc/structure.cc
+ ../idlc/block.cc
+ ../idlc/generator.cc
+ ../idlc/proxy_gen.cc
+ ../idlc/stub_gen.cc
+ )
+
+SET(UNIT_TESTS_SOURCES
+ document_unittest.cc
+ block_unittest.cc
+ type_unittest.cc
+ attribute_unittest.cc
+ declaration_unittest.cc
+ interface_unittest.cc
+ structure_unittest.cc
+ generator_unittest.cc
+ proxy_gen_unittest.cc
+ stub_gen_unittest.cc
+ main.cc
+ )
+
+ADD_EXECUTABLE(tidl-unit-tests
+ ${TIDLC_SOURCES}
+ ${UNIT_TESTS_SOURCES}
+ )
+
+TARGET_LINK_LIBRARIES(tidl-unit-tests ${GTEST_LIBRARIES} pthread)
+
+INSTALL(TARGETS tidl-unit-tests DESTINATION bin)
+
+SET(TIDL_UNIT_TESTS tidl-unit-tests)
+ADD_TEST(NAME ${TIDL_UNIT_TESTS} COMMAND ${TIDL_UNIT_TESTS})
+ADD_CUSTOM_COMMAND(
+ TARGET ${TIDL_UNIT_TESTS}
+ COMMENT "Run Unit Tests"
+ POST_BUILD
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${TIDL_UNIT_TESTS})
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/attribute.h"
+
+class AttributeTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(AttributeTest, Attribute_Contstructor) {
+ tidl::Attribute* attr = new tidl::Attribute("test",
+ new tidl::BaseType("int"));
+ EXPECT_NE(attr, nullptr);
+ delete attr;
+}
+
+TEST_F(AttributeTest, Attribute_GetID) {
+ tidl::Attribute* attr = new tidl::Attribute("test",
+ new tidl::BaseType("int"));
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attr->GetID(), "test");
+ delete attr;
+}
+
+TEST_F(AttributeTest, Attribute_GetType) {
+ tidl::Attribute* attr = new tidl::Attribute("test",
+ new tidl::BaseType("int"));
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attr->GetType().ToString(), "int");
+ delete attr;
+}
+
+class AttributesTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(AttributesTest, Attributes_Constructor) {
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ delete attrs;
+}
+
+TEST_F(AttributesTest, Attributes_Add) {
+ tidl::Attribute* attr = new tidl::Attribute("test",
+ new tidl::BaseType("int"));
+ EXPECT_NE(attr, nullptr);
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(attr);
+
+ bool flag = false;
+ for (auto& attr : attrs->GetAttrs()) {
+ if (attr->GetID() == "test" &&
+ attr->GetType().ToString() == "int")
+ flag = true;
+ }
+ EXPECT_EQ(flag, true);
+ delete attrs;
+}
+
+TEST_F(AttributesTest, Attributes_GetAttrs) {
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("test1", new tidl::BaseType("int")));
+ attrs->Add(new tidl::Attribute("test2", new tidl::BaseType("char *")));
+
+ int count = 0;
+ for (auto& attr : attrs->GetAttrs()) {
+ if (attr->GetID() == "test1" &&
+ attr->GetType().ToString() == "int")
+ count++;
+ if (attr->GetID() == "test2" &&
+ attr->GetType().ToString() == "char *")
+ count++;
+ }
+ EXPECT_EQ(count, 2);
+ delete attrs;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/block.h"
+
+class BlockTest : public testing::Test {
+ public:
+ tidl::Block* testBlock;
+
+ virtual void SetUp() {
+ testBlock = new tidl::Block("TestBlock", tidl::Block::TYPE_INTERFACE);
+ }
+ virtual void TearDown() {
+ delete testBlock;
+ }
+};
+
+TEST_F(BlockTest, Block_Constructor) {
+ tidl::Block* block = new tidl::Block("StructureBlock",
+ tidl::Block::TYPE_STRUCTURE);
+ EXPECT_NE(block, nullptr);
+ delete block;
+}
+
+TEST_F(BlockTest, Block_GetID) {
+ EXPECT_EQ(testBlock->GetID(), "TestBlock");
+}
+
+TEST_F(BlockTest, Block_GetType) {
+ EXPECT_EQ(testBlock->GetType(), tidl::Block::TYPE_INTERFACE);
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/declaration.h"
+#include "idlc/type.h"
+#include "idlc/parameter.h"
+
+class DeclarationTest : public testing::Test {
+ public:
+ tidl::Parameters* params;
+
+ virtual void SetUp() {
+ params = new tidl::Parameters();
+ EXPECT_NE(params, nullptr);
+ params->Add(new tidl::Parameter("test1",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+ params->Add(new tidl::Parameter("test2",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+ }
+ virtual void TearDown() {}
+};
+
+TEST_F(DeclarationTest, Declaration_Constructor) {
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+ delete decl;
+}
+
+TEST_F(DeclarationTest, Declaration_GetID) {
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+ EXPECT_EQ(decl->GetID(), "test");
+ delete decl;
+}
+
+TEST_F(DeclarationTest, Declaration_GetType) {
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+ EXPECT_EQ(decl->GetType().ToString(), "int");
+ delete decl;
+}
+
+TEST_F(DeclarationTest, Declaration_GetParameters) {
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+
+ int count = 0;
+ for (auto& param : decl->GetParameters().GetParams()) {
+ if (param->GetID() == "test1" &&
+ param->GetParameterType().GetBaseType().ToString() == "int")
+ count++;
+ if (param->GetID() == "test2" &&
+ param->GetParameterType().GetBaseType().ToString() == "int")
+ count++;
+ }
+ EXPECT_EQ(count, 2);
+
+ delete decl;
+}
+
+TEST_F(DeclarationTest, Declaration_IsAsync) {
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+ EXPECT_EQ(decl->IsAsync(), false);
+ delete decl;
+}
+
+class DeclarationsTest : public testing::Test {
+ public:
+ tidl::Declaration* decl;
+
+ virtual void SetUp() {}
+ virtual void TestDown() {}
+ void PrepareDeclaration() {
+ tidl::Parameters* params = new tidl::Parameters();
+ EXPECT_NE(params, nullptr);
+ params->Add(new tidl::Parameter("test1",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+ params->Add(new tidl::Parameter("test2",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+ decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+ }
+};
+
+TEST_F(DeclarationsTest, Declarations_Constructor) {
+ tidl::Declarations* decls = new tidl::Declarations();
+ EXPECT_NE(decls, nullptr);
+ delete decls;
+}
+
+TEST_F(DeclarationsTest, Declarations_Add) {
+ tidl::Declarations* decls = new tidl::Declarations();
+ EXPECT_NE(decls, nullptr);
+ PrepareDeclaration();
+ decls->Add(decl);
+
+ bool flag = false;
+ for (auto& d : decls->GetDecls()) {
+ if (d->GetID() == "test")
+ flag = true;
+ }
+ EXPECT_EQ(flag, true);
+ delete decls;
+}
+
+TEST_F(DeclarationsTest, Declarations_GetDecls) {
+ tidl::Declarations* decls = new tidl::Declarations();
+ EXPECT_NE(decls, nullptr);
+ PrepareDeclaration();
+ decls->Add(decl);
+
+ bool flag = false;
+ for (auto& d : decls->GetDecls()) {
+ if (d->GetID() == "test")
+ flag = true;
+ }
+ EXPECT_EQ(flag, true);
+ delete decls;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/document.h"
+#include "idlc/block.h"
+
+class DocumentTest : public testing::Test {
+ public:
+ tidl::Block* block;
+ tidl::Document* document;
+
+ virtual void SetUp() {
+ document = new tidl::Document();
+ block = new tidl::Block("TestBlock", tidl::Block::TYPE_INTERFACE);
+ }
+ virtual void TearDown() {
+ }
+};
+
+TEST_F(DocumentTest, Document_Constructor) {
+ tidl::Document *doc = new tidl::Document();
+ EXPECT_NE(doc, nullptr);
+ delete doc;
+}
+
+TEST_F(DocumentTest, Document_AddBlock) {
+ document->AddBlock(block);
+ bool flag = false;
+ for (auto& blk : document->GetBlocks()) {
+ if (blk->GetID() == "TestBlock")
+ flag = true;
+ }
+ EXPECT_NE(flag, false);
+}
+
+TEST_F(DocumentTest, Document_GetBlocks) {
+ document->AddBlock(block);
+ bool flag = false;
+ for (auto& blk : document->GetBlocks()) {
+ if (blk->GetType() == tidl::Block::TYPE_INTERFACE)
+ flag = true;
+ }
+ EXPECT_NE(flag, false);
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/generator.h"
+#include "idlc/interface.h"
+#include "idlc/structure.h"
+
+class SampleGenerator : public tidl::Generator {
+ public:
+ SampleGenerator(std::shared_ptr<tidl::Document> doc)
+ : tidl::Generator(doc), count_(0) {}
+ ~SampleGenerator() {}
+
+ void OnInterfaceBegin(const std::string& id) override {
+ interfaceID_ = id;
+ count_++;
+ }
+ void OnInterfaceEnd(const std::string& id) override {
+ count_++;
+ }
+ void OnDeclarationGen(std::ofstream& stream, const std::string& id,
+ const tidl::Parameters& args,
+ const tidl::BaseType& ret) override {
+ count_++;
+ }
+ void OnStructureBegin(std::ofstream& stream, const std::string& id) override {
+ structureID_ = id;
+ count_++;
+ }
+ void OnStructureEnd(std::ofstream& stream, const std::string& id) override {
+ count_++;
+ }
+ void OnAttributeGen(std::ofstream& stream, const std::string& id,
+ const tidl::BaseType& type) override {
+ count_++;
+ }
+ void OnInitGen(std::ofstream& stream) override {
+ count_++;
+ }
+ void OnFiniGen(std::ofstream& stream) override {
+ count_++;
+ }
+
+ const int GetCount() const {
+ return count_;
+ }
+
+ const std::string& GetInterfaceID() const {
+ return interfaceID_;
+ }
+
+ const std::string& GetStructureID() const {
+ return structureID_;
+ }
+
+ private:
+ int count_;
+ std::string interfaceID_;
+ std::string structureID_;
+};
+
+class GeneratorTest : public testing::Test {
+ public:
+ tidl::Document* doc;
+
+ virtual void SetUp() {
+ tidl::Parameters* params = new tidl::Parameters();
+ EXPECT_NE(params, nullptr);
+ params->Add(new tidl::Parameter("test",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+
+ tidl::Declarations* decls = new tidl::Declarations();
+ EXPECT_NE(decls, nullptr);
+ decls->Add(decl);
+
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int")));
+
+ doc = new tidl::Document();
+ EXPECT_NE(doc, nullptr);
+ doc->AddBlock(new tidl::Interface("TestInterface", decls));
+ doc->AddBlock(new tidl::Structure("TestStructure", attrs));
+ }
+ virtual void TearDown() {}
+};
+
+TEST_F(GeneratorTest, Generator_Constructor) {
+ std::shared_ptr<tidl::Document> docPtr(doc);
+ SampleGenerator* sampleGen = new SampleGenerator(docPtr);
+ EXPECT_NE(sampleGen, nullptr);
+ delete sampleGen;
+}
+
+TEST_F(GeneratorTest, Generator_Run) {
+ std::shared_ptr<tidl::Document> docPtr(doc);
+ SampleGenerator* sampleGen = new SampleGenerator(docPtr);
+ EXPECT_NE(sampleGen, nullptr);
+ sampleGen->Run("test.txt");
+ EXPECT_EQ(sampleGen->GetCount(), 8);
+ EXPECT_EQ(sampleGen->GetInterfaceID(), "TestInterface");
+ EXPECT_EQ(sampleGen->GetStructureID(), "TestStructure");
+ delete sampleGen;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/interface.h"
+
+class InterfaceTest : public testing::Test {
+ public:
+ tidl::Declarations* decls;
+
+ virtual void SetUp() {
+ tidl::Parameters* params = new tidl::Parameters();
+ EXPECT_NE(params, nullptr);
+ params->Add(new tidl::Parameter("test1",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+ params->Add(new tidl::Parameter("test2",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+ decls = new tidl::Declarations();
+ EXPECT_NE(decls, nullptr);
+ decls->Add(decl);
+ }
+ virtual void TearDown() {}
+};
+
+TEST_F(InterfaceTest, Interface_Constructor) {
+ tidl::Interface* interface = new tidl::Interface("TestInterface", decls);
+ EXPECT_NE(interface, nullptr);
+ delete interface;
+}
+
+TEST_F(InterfaceTest, Interface_GetDeclrations) {
+ tidl::Interface* interface = new tidl::Interface("TestInterface", decls);
+ EXPECT_NE(interface, nullptr);
+
+ bool flag = false;
+ for (auto& d : interface->GetDeclarations().GetDecls()) {
+ if (d->GetID() == "test")
+ flag = true;
+ }
+ EXPECT_EQ(flag, true);
+ delete interface;
+}
+
+TEST_F(InterfaceTest, Interface_GetID) {
+ tidl::Interface* interface = new tidl::Interface("TestInterface", decls);
+ EXPECT_NE(interface, nullptr);
+ EXPECT_EQ(interface->GetID(), "TestInterface");
+ delete interface;
+}
+
+TEST_F(InterfaceTest, Interface_GetType) {
+ tidl::Interface* interface = new tidl::Interface("TestInterface", decls);
+ EXPECT_NE(interface, nullptr);
+ EXPECT_EQ(interface->GetType(), tidl::Interface::TYPE_INTERFACE);
+ delete interface;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/proxy_gen.h"
+#include "idlc/interface.h"
+#include "idlc/structure.h"
+
+class ProxyGenTest : public testing::Test {
+ public:
+ tidl::Document* doc;
+
+ virtual void SetUp() {
+ tidl::Parameters* params = new tidl::Parameters();
+ EXPECT_NE(params, nullptr);
+ params->Add(new tidl::Parameter("test",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+
+ tidl::Declarations* decls = new tidl::Declarations();
+ EXPECT_NE(decls, nullptr);
+ decls->Add(decl);
+
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int")));
+
+ doc = new tidl::Document();
+ EXPECT_NE(doc, nullptr);
+ doc->AddBlock(new tidl::Interface("TestInterface", decls));
+ doc->AddBlock(new tidl::Structure("TestStructure", attrs));
+ }
+ virtual void TearDown() {}
+
+ bool IsExistence(const std::string& file) const {
+ if (std::ifstream(file))
+ return true;
+
+ return false;
+ }
+};
+
+TEST_F(ProxyGenTest, ProxyGen_Constructor) {
+ std::shared_ptr<tidl::Document> docPtr(doc);
+ tidl::ProxyGen* gen = new tidl::ProxyGen(docPtr);
+ EXPECT_NE(gen, nullptr);
+ delete gen;
+}
+
+TEST_F(ProxyGenTest, ProxyGen_Run) {
+ std::shared_ptr<tidl::Document> docPtr(doc);
+ tidl::ProxyGen* gen = new tidl::ProxyGen(docPtr);
+ EXPECT_NE(gen, nullptr);
+ gen->Run("ProxyGen.txt");
+ EXPECT_EQ(IsExistence("ProxyGen.txt"), true);
+ delete gen;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/structure.h"
+
+class StructureTest : public testing::Test {
+ public:
+ tidl::Attributes* attrs;
+
+ virtual void SetUp() {
+ attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("test1", new tidl::BaseType("int")));
+ attrs->Add(new tidl::Attribute("test2", new tidl::BaseType("char *")));
+ }
+ virtual void TearDown() {}
+};
+
+TEST_F(StructureTest, Structure_Constructor) {
+ tidl::Structure* structure = new tidl::Structure("TestStructure", attrs);
+ EXPECT_NE(structure, nullptr);
+ delete structure;
+}
+
+TEST_F(StructureTest, Structure_GetAttributes) {
+ tidl::Structure* structure = new tidl::Structure("TestStructure", attrs);
+ EXPECT_NE(structure, nullptr);
+
+ int count = 0;
+ for (auto& attr : attrs->GetAttrs()) {
+ if (attr->GetID() == "test1" &&
+ attr->GetType().ToString() == "int")
+ count++;
+ if (attr->GetID() == "test2" &&
+ attr->GetType().ToString() == "char *")
+ count++;
+ }
+ EXPECT_EQ(count, 2);
+ delete structure;
+}
+
+TEST_F(StructureTest, Structure_GetID) {
+ tidl::Structure* structure = new tidl::Structure("TestStructure", attrs);
+ EXPECT_NE(structure, nullptr);
+ EXPECT_EQ(structure->GetID(), "TestStructure");
+ delete structure;
+}
+
+TEST_F(StructureTest, Structure_GetType) {
+ tidl::Structure* structure = new tidl::Structure("TestStructure", attrs);
+ EXPECT_NE(structure, nullptr);
+ EXPECT_EQ(structure->GetType(), tidl::Structure::TYPE_STRUCTURE);
+ delete structure;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/stub_gen.h"
+#include "idlc/interface.h"
+#include "idlc/structure.h"
+
+class StubGenTest : public testing::Test {
+ public:
+ tidl::Document* doc;
+
+ virtual void SetUp() {
+ tidl::Parameters* params = new tidl::Parameters();
+ EXPECT_NE(params, nullptr);
+ params->Add(new tidl::Parameter("test",
+ new tidl::ParameterType(new tidl::BaseType("int"))));
+
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int"), params);
+ EXPECT_NE(decl, nullptr);
+
+ tidl::Declarations* decls = new tidl::Declarations();
+ EXPECT_NE(decls, nullptr);
+ decls->Add(decl);
+
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("test", new tidl::BaseType("int")));
+
+ doc = new tidl::Document();
+ EXPECT_NE(doc, nullptr);
+ doc->AddBlock(new tidl::Interface("TestInterface", decls));
+ doc->AddBlock(new tidl::Structure("TestStructure", attrs));
+ }
+ virtual void TearDown() {}
+};
+
+TEST_F(StubGenTest, StubGen_Constructor) {
+ std::shared_ptr<tidl::Document> docPtr(doc);
+ tidl::StubGen* gen = new tidl::StubGen(docPtr);
+ EXPECT_NE(gen, nullptr);
+ delete gen;
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include "idlc/type.h"
+
+class TokenTest : public testing::Test {
+ public:
+ tidl::Token* testToken;
+
+ virtual void SetUp() {
+ testToken = new tidl::Token("TestToken");
+ }
+ virtual void TearDown() {
+ delete testToken;
+ }
+};
+
+TEST_F(TokenTest, Token_Constructor) {
+ tidl::Token* token = new tidl::Token("TestToken");
+ EXPECT_NE(token, nullptr);
+ delete token;
+}
+
+TEST_F(TokenTest, Token_ToString) {
+ EXPECT_EQ(testToken->ToString(), "TestToken");
+}
+
+class BaseTypeTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(BaseTypeTest, BaseType_Constructor) {
+ tidl::BaseType* baseType = new tidl::BaseType("BaseType");
+ EXPECT_NE(baseType, nullptr);
+ delete baseType;
+}
+
+TEST_F(BaseTypeTest, BaseType_SetMetaType) {
+ tidl::BaseType* customType = new tidl::BaseType("CustomType", true);
+ customType->SetMetaType(new tidl::BaseType("int"));
+ EXPECT_EQ(customType->GetMetaType().ToString(), "int");
+ delete customType;
+}
+
+TEST_F(BaseTypeTest, BaseType_GetMetaType) {
+ tidl::BaseType* customType = new tidl::BaseType("CustomType", true);
+ customType->SetMetaType(new tidl::BaseType("string"));
+ EXPECT_EQ(customType->GetMetaType().ToString(), "string");
+ delete customType;
+}
+
+TEST_F(BaseTypeTest, BaseType_GetFullName) {
+ tidl::BaseType* customType = new tidl::BaseType("CustomType", true);
+ customType->SetMetaType(new tidl::BaseType("string"));
+ EXPECT_EQ(customType->GetFullName(), "CustomType<string>");
+ delete customType;
+}
+
+TEST_F(BaseTypeTest, BaseType_IsUserDefinedType) {
+ tidl::BaseType* testType = new tidl::BaseType("TestType", true);
+ EXPECT_EQ(testType->IsUserDefinedType(), true);
+ delete testType;
+}
+
+class ParameterTypeTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(ParameterTypeTest, ParameterType_Constructor) {
+ tidl::ParameterType *parameterType = new tidl::ParameterType(
+ new tidl::BaseType("int"));
+ EXPECT_NE(parameterType, nullptr);
+ delete parameterType;
+}
+
+TEST_F(ParameterTypeTest, ParameterType_Constructor_With_Direction) {
+ tidl::ParameterType *parameterType = new tidl::ParameterType(
+ new tidl::BaseType("int"), "in");
+ EXPECT_NE(parameterType, nullptr);
+ delete parameterType;
+}
+
+TEST_F(ParameterTypeTest, ParameterType_GetDirection) {
+ tidl::ParameterType *parameterType = new tidl::ParameterType(
+ new tidl::BaseType("int"), "out");
+ EXPECT_NE(parameterType, nullptr);
+ EXPECT_EQ(parameterType->GetDirection(), tidl::ParameterType::Direction::OUT);
+ delete parameterType;
+}
+
+TEST_F(ParameterTypeTest, ParameterType_GetBaseType) {
+ tidl::ParameterType *parameterType = new tidl::ParameterType(
+ new tidl::BaseType("string"), "ref");
+ EXPECT_NE(parameterType, nullptr);
+ EXPECT_EQ(parameterType->GetBaseType().ToString(),
+ "string");
+ delete parameterType;
+}
--- /dev/null
+#!/bin/bash
+
+#--------------------------------------------------------#
+# Tizen Interface Definition Langauge Compiler Unit Test #
+#--------------------------------------------------------#
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+SCRIPT_FILE=$(readlink -f $0)
+SCRIPT_DIR=$(dirname $SCRIPT_FILE)
+BUILD_DIR=build
+
+usage() {
+ echo "Usage: $0 [command]"
+ echo "Commands:"
+ echo " build Build the unit tests"
+ echo " clean Clean all artifacts"
+ echo " run Run the unit tests"
+ echo " full Build & Run the unit tests"
+}
+
+cmd_build() {
+ echo "[TIDL Unit Test] Build Unit Tests"
+ mkdir -p $SCRIPT_DIR/$BUILD_DIR
+ cd $SCRIPT_DIR/$BUILD_DIR
+ cmake ..
+ make
+}
+
+cmd_clean() {
+ echo "[TIDL Unit Test] Clean all artifacts"
+ rm -rf $SCRIPT_DIR/$BUILD_DIR
+}
+
+cmd_run() {
+ echo "[TIDL Unit Test] Run Unit Tests"
+ cd $SCRIPT_DIR/$BUILD_DIR
+ $SCRIPT_DIR/$BUILD_DIR/tidl-unit-tests
+ cd $SCRIPT_DIR
+}
+
+cmd_full() {
+ cmd_build
+ cmd_run
+ cmd_clean
+}
+
+cmd=$1; shift;
+case "$cmd" in
+ build|--build|-b) cmd_build $@ ;;
+ clean|--clean|-c) cmd_clean $@ ;;
+ run|--run|-r) cmd_run $@ ;;
+ full |--full |-f) cmd_full $@ ;;
+ *) usage ;;
+
+esac