When building this package, the tidl-build-tests is also built together.
Before building the codes, the tidl-build-tests generates the codes using tidlc.
The tidl files exist in the tests/buil_tests/tidl directory.
The unit_tests is moved to the tests/unit_tests.
Change-Id: I2816d93468582cdbf1aae3c067667104e3be3d52
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
IF(NOT DEFINED MINIMUM_BUILD)
ENABLE_TESTING()
-SET(TIDL_UNIT_TESTS tidl-unit-tests)
+SET(TARGET_TIDL_BUILD_TESTS "tidl-build-tests")
+SET(TIDL_UNIT_TESTS "tidl-unit-tests")
ADD_TEST(NAME ${TIDL_UNIT_TESTS} COMMAND ${TIDL_UNIT_TESTS} test.tidl test_error.tidl
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unit_tests)
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/unit_tests)
ENDIF(NOT DEFINED MINIMUM_BUILD)
ADD_SUBDIRECTORY(idlc)
-IF(NOT DEFINED MINIMUM_BUILD)
-ADD_SUBDIRECTORY(unit_tests)
-ADD_DEPENDENCIES(${TIDL_UNIT_TESTS} ${PROJECT_NAME})
-ENDIF(NOT DEFINED MINIMUM_BUILD)
+ADD_SUBDIRECTORY(tests)
BuildRequires: bison
BuildRequires: gtest-devel
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(rpc-port)
+BuildRequires: pkgconfig(bundle)
%if 0%{?gcov:1}
BuildRequires: lcov
%endif
%__make %{?_smp_mflags}
%check
-ctest --output-on-failure %{?_smp_mflags}
+ctest -V %{?_smp_mflags}
%if 0%{?gcov:1}
lcov -c --ignore-errors graph --no-external -q -d . -o gcov.info
genhtml gcov.info
--- /dev/null
+IF(NOT DEFINED MINIMUM_BUILD)
+ADD_SUBDIRECTORY(unit_tests)
+ADD_DEPENDENCIES(${TIDL_UNIT_TESTS} ${PROJECT_NAME})
+
+ADD_SUBDIRECTORY(build_tests)
+ADD_DEPENDENCIES(${TARGET_TIDL_BUILD_TESTS} ${PROJECT_NAME})
+ENDIF(NOT DEFINED MINIMUM_BUILD)
--- /dev/null
+SET(TOOL_TIDLC "${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/tidlc")
+SET(TARGET_PREBUILD_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/prebuild.sh")
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(PKGS REQUIRED dlog glib-2.0 rpc-port bundle)
+
+FOREACH(flag ${PKGS_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFALGS} -fPIE -Werror")
+SET(CMAKE_EXE_LINKER_FLAGS "-pie -Wl,--as-needed")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TIDL_BUILD_TESTS_SRCS)
+
+SET(TIDL_GEN_SRCS
+ BufferProxy.cc
+ BufferProxyC.c
+ BufferStub.cc
+ BufferStubC.c
+ DataPortProxy.cc
+ DataPortProxyC.c
+ DataPortStub.cc
+ DataPortStubC.c
+ ExProxy.cc
+ ExProxyC.c
+ ExStub.cc
+ ExStubC.c
+ MessageProxy.cc
+ MessageProxyC.c
+ MessageStub.cc
+ MessageStubC.c
+)
+
+ADD_CUSTOM_COMMAND(OUTPUT ${TIDL_GEN_SRCS} PRE_BUILD
+ COMMAND ${TARGET_PREBUILD_SCRIPT} ${TOOL_TIDLC} ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS ${TOOL_TIDLC}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+ADD_EXECUTABLE(${TARGET_TIDL_BUILD_TESTS}
+ ${TIDL_BUILD_TESTS_SRCS}
+ ${TIDL_GEN_SRCS}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_TIDL_BUILD_TESTS} ${PKGS_LDFLAGS} "-lpthread")
+
+INSTALL(TARGETS ${TARGET_TIDL_BUILD_TESTS} DESTINATION bin)
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <iostream>
+
+int main(int argc, char** argv) {
+ std::cout << "TIDL Build Test" << std::endl;
+ return 0;
+}
--- /dev/null
+#!/bin/bash
+
+SCRIPT_FILE=$(readlink -f $0)
+SCRIPT_DIR=$(dirname $SCRIPT_FILE)
+TIDLC=$1
+TARGET_DIR=$2
+
+FILES[0]="Message"
+FILES[1]="Buffer"
+FILES[2]="Ex"
+FILES[3]="DataPort"
+FILES[4]="Foo"
+
+GenerateTIDL() {
+ for index in ${!FILES[*]}; do
+ echo "Generate ${FILES[index]}"
+
+ INPUT="${FILES[index]}.tidl"
+ OUTPUT="${FILES[index]}Stub"
+ ${TIDLC} -s -l C++ -i ${SCRIPT_DIR}/tidl/${INPUT} -o ${TARGET_DIR}/${OUTPUT}
+
+ OUTPUT="${FILES[index]}Proxy"
+ ${TIDLC} -p -l C++ -i ${SCRIPT_DIR}/tidl/${INPUT} -o ${TARGET_DIR}/${OUTPUT}
+
+ OUTPUT="${FILES[index]}StubC"
+ ${TIDLC} -s -n -l C -i ${SCRIPT_DIR}/tidl/${INPUT} -o ${TARGET_DIR}/${OUTPUT}
+
+ OUTPUT="${FILES[index]}ProxyC"
+ ${TIDLC} -p -n -l C -i ${SCRIPT_DIR}/tidl/${INPUT} -o ${TARGET_DIR}/${OUTPUT}
+ done
+}
+
+GenerateTIDL
+
+echo "Done"
--- /dev/null
+interface IRemoteBuffer {
+ void BufEvent(array<char> buf) delegate;
+
+ int GetFirst(string id, BufEvent ev, int max_size);
+ int GetNext(string id);
+}
--- /dev/null
+struct CursorContext {
+ int Handle;
+}
+
+struct Pair {
+ string Key;
+ string Value;
+}
+
+interface DataPort {
+ CursorContext Query(string uri, list<string> projection, string selection, list<string> selectionArgs, string sortOrder);
+ int Insert(string uri, list<Pair> values);
+ int Update(string uri, list<Pair> values, string selection, list<string> selectionArgs);
+ int Delete(string uri, string selection, list<string> selectionArgs);
+
+ bool CursorIsLast(CursorContext cxt);
+ bool CursorMoveToFirst(CursorContext cxt);
+ bool CursorMoveToNext(CursorContext cxt);
+ string CursorGetString(CursorContext cxt, int column);
+ void CursorDispose(CursorContext cxt) async;
+}
--- /dev/null
+struct StructTest {
+ int Int;
+ short Short;
+ char Char;
+ bundle Bd;
+ bool Fg;
+ string Str;
+ float Float;
+ double Double;
+ long Long;
+}
+
+struct Student {
+ string name;
+ int num;
+ bundle data;
+ array<char> extra;
+}
+
+struct Class {
+ string name;
+ list<Student> students;
+}
+
+[privilege = "http://tizen.org/privilege/appmanager.launch", privilege = "http://tizen.org/privilege/mediastorage",
+trusted = "true"]
+interface School {
+ void ClassAddedCB(int ret) delegate;
+ int T1(out bool b);
+ int T2(out char c);
+ int T3(out int l);
+ int T4(ref bool b);
+ int T5(ref char c);
+ int T6(ref int l);
+ int T7(out string str);
+ int T8(ref string str);
+ int Test1(out StructTest st);
+ int Test2(StructTest st);
+ int Test3(ref StructTest st);
+ int Test4(out list<StructTest> st);
+ int Test5(list<StructTest> st);
+ int Test6(ref list<StructTest> st);
+
+ /// <summary>
+ /// Add class
+ /// </summary>
+ int AddClass(in Class cls);
+
+ /// <summary>
+ /// Add class async
+ /// </summary>
+ void AddClassAsync(Class cls, ClassAddedCB cb) async;
+
+ int GetStudent(in string c_name, in string s_name, out Student student);
+ int SetAllIds(list<list<int>> nums);
+ int SetExtra(string s_name, array<char> extra);
+}
--- /dev/null
+struct Foo {
+ int Age;
+ string Name;
+}
+
+interface Runnable {
+ int Run(Foo foo);
+ list<string> GetNames();
+}
--- /dev/null
+interface Message {
+ void NotifyCB(string sender, string msg) delegate;
+
+ int Register(string name, NotifyCB cb);
+ void Unregister() async;
+ int Send(string msg);
+}
--- /dev/null
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
+
+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(${GTEST_INCLUDE_DIRS})
+LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS})
+
+SET(TIDLC_SOURCES
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/document.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/declaration.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/interface.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/type.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/parameter.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/element.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/structure.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/block.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/gen/generator.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/parser.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/attribute.cc
+ )
+
+ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"")
+
+AUX_SOURCE_DIRECTORY(. UNIT_TESTS_SOURCES)
+AUX_SOURCE_DIRECTORY(cs_gen CS_GEN_UNIT_TESTS_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/gen CS_GEN_SOURCES)
+
+FLEX_TARGET(TIDLC ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/tidlc.ll
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/tidlc_l.cpp)
+BISON_TARGET(TIDLC ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/tidlc.yy
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../idlc/ast/tidlc_y.cpp)
+
+ADD_EXECUTABLE(${TIDL_UNIT_TESTS}
+ ${BISON_TIDLC_OUTPUTS}
+ ${FLEX_TIDLC_OUTPUTS}
+ ${TIDLC_SOURCES}
+ ${CS_GEN_SOURCES}
+ ${UNIT_TESTS_SOURCES}
+ ${CS_GEN_UNIT_TESTS_SOURCES}
+ )
+TARGET_LINK_LIBRARIES(${TIDL_UNIT_TESTS} ${GTEST_LIBRARIES} pthread)
+
+INSTALL(TARGETS ${TIDL_UNIT_TESTS} DESTINATION bin)
+INSTALL(FILES test.tidl DESTINATION /opt/usr/share/tidl-unit-tests)
+INSTALL(FILES test_error.tidl DESTINATION /opt/usr/share/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/ast/attribute.h"
+
+class AttributeTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(AttributeTest, Attribute_Constructor) {
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
+ EXPECT_NE(attr, nullptr);
+ delete attr;
+}
+
+TEST_F(AttributeTest, Attribute_GetKey) {
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attr->GetKey(), "key");
+ delete attr;
+}
+
+TEST_F(AttributeTest, Attribute_GetValue) {
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attr->GetValue(), "value");
+ delete attr;
+}
+
+TEST_F(AttributeTest, Attribute_GetLine) {
+ unsigned line = __LINE__;
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", line);
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attr->GetLine(), line);
+ 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::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("key", "value", __LINE__));
+
+ bool flag = false;
+ for (auto& attr : attrs->GetAttrs()) {
+ if (attr->GetKey() == "key" &&
+ attr->GetValue() == "value")
+ 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("key1", "value1", __LINE__));
+ attrs->Add(new tidl::Attribute("key2", "value2", __LINE__));
+
+ int count = 0;
+ for (auto& attr : attrs->GetAttrs()) {
+ if (attr->GetKey() == "key1" &&
+ attr->GetValue() == "value1")
+ count++;
+ if (attr->GetKey() == "key2" &&
+ attr->GetValue() == "value2")
+ count++;
+ }
+ EXPECT_EQ(count, 2);
+ delete attrs;
+}
+
+TEST_F(AttributesTest, Attributes_Exist) {
+ tidl::Attributes* attrs = new tidl::Attributes();
+ EXPECT_NE(attrs, nullptr);
+ attrs->Add(new tidl::Attribute("key", "value", __LINE__));
+ tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
+ EXPECT_NE(attr, nullptr);
+ EXPECT_EQ(attrs->Exist(attr), true);
+ delete attr;
+ 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/ast/block.h"
+
+class BlockTest : public testing::Test {
+ public:
+ tidl::Block* testBlock;
+
+ virtual void SetUp() {
+ testBlock = new tidl::Block("TestBlock", tidl::Block::TYPE_INTERFACE,
+ "", 28);
+ }
+ virtual void TearDown() {
+ delete testBlock;
+ }
+};
+
+TEST_F(BlockTest, Block_Constructor) {
+ tidl::Block* block = new tidl::Block("StructureBlock",
+ tidl::Block::TYPE_STRUCTURE, "", __LINE__);
+ 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);
+}
+
+TEST_F(BlockTest, Block_GetLine) {
+ EXPECT_EQ(testBlock->GetLine(), 28);
+}
+
+TEST_F(BlockTest, Block_GetComments) {
+ std::string comments = "Test Block";
+ tidl::Block* block = new tidl::Block("StructureBlock",
+ tidl::Block::TYPE_STRUCTURE, comments, __LINE__);
+ EXPECT_NE(block, nullptr);
+ EXPECT_EQ(block->GetComments(), comments);
+ delete block;
+}
--- /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/ast/parser.h"
+#include "idlc/gen/cs_proxy_gen.h"
+
+class CsProxyGenTest : public testing::Test {
+ public:
+ tidl::Parser* ps = nullptr;
+
+ virtual void SetUp() {
+ ps = new tidl::Parser();
+ }
+
+ virtual void TearDown() {
+ delete ps;
+ }
+
+ bool FindStringFromFile(std::string filename, std::string str) {
+ std::ifstream cb_file(filename);
+ std::string line;
+
+ while (std::getline(cb_file, line)) {
+ if (line.find(str) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+};
+
+TEST_F(CsProxyGenTest, CsProxyGen_Constructor) {
+ bool ret = ps->ParseFromFile("test.tidl");
+ ASSERT_TRUE(ret);
+ tidl::CsProxyGen gen(ps->GetDoc());
+}
+
+TEST_F(CsProxyGenTest, CsProxyGen_Run) {
+ bool ret = ps->ParseFromFile("test.tidl");
+ ASSERT_TRUE(ret);
+ tidl::CsProxyGen gen(ps->GetDoc());
+ gen.Run("test.cs");
+
+ ASSERT_TRUE(FindStringFromFile("test.cs", "namespace RPCPort"));
+ ASSERT_TRUE(FindStringFromFile("test.cs",
+ " public sealed class Student"));
+ ASSERT_TRUE(FindStringFromFile("test.cs",
+ " public string name { get; set; }"));
+ ASSERT_TRUE(FindStringFromFile("test.cs", " public sealed class Class"));
+ ASSERT_TRUE(FindStringFromFile("test.cs",
+ " public LinkedList<Student> students { get; set; }"));
+}
--- /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/ast/parser.h"
+#include "idlc/gen/cs_stub_gen.h"
+
+class CsStubGenTest : public testing::Test {
+ public:
+ tidl::Parser* ps = nullptr;
+
+ virtual void SetUp() {
+ ps = new tidl::Parser();
+ }
+
+ virtual void TearDown() {
+ delete ps;
+ }
+
+ bool FindStringFromFile(std::string filename, std::string str) {
+ std::ifstream cb_file(filename);
+ std::string line;
+
+ while (std::getline(cb_file, line)) {
+ if (line.find(str) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+};
+
+TEST_F(CsStubGenTest, CsStubGen_Constructor) {
+ bool ret = ps->ParseFromFile("test.tidl");
+ ASSERT_TRUE(ret);
+ tidl::CsStubGen gen(ps->GetDoc());
+}
+
+TEST_F(CsStubGenTest, CsStubGen_Run) {
+ bool ret = ps->ParseFromFile("test.tidl");
+ ASSERT_TRUE(ret);
+ tidl::CsStubGen gen(ps->GetDoc());
+ gen.Run("test_stub.cs");
+
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs", "namespace RPCPort"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " public sealed class Student"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " public string name { get; set; }"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " public sealed class Class"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " public LinkedList<Student> students { get; set; }"));
+}
--- /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/ast/declaration.h"
+#include "idlc/ast/type.h"
+#include "idlc/ast/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", "")), __LINE__));
+ params->Add(new tidl::Parameter("test2",
+ new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
+ }
+ virtual void TearDown() {}
+};
+
+TEST_F(DeclarationTest, Declaration_Constructor) {
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int", ""), params, "", __LINE__);
+ EXPECT_NE(decl, nullptr);
+ delete decl;
+}
+
+TEST_F(DeclarationTest, Declaration_GetID) {
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int", ""), params, "", __LINE__);
+ 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, "", __LINE__);
+ 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, "", __LINE__);
+ 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_GetMethodType) {
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int", ""), params, "", __LINE__,
+ tidl::Declaration::MethodType::DELEGATE);
+ EXPECT_NE(decl, nullptr);
+ EXPECT_EQ(decl->GetMethodType(), tidl::Declaration::MethodType::DELEGATE);
+ delete decl;
+}
+
+TEST_F(DeclarationTest, Declaration_GetComments) {
+ std::string comments = "Test Declaration";
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int", ""), params, comments, __LINE__);
+ EXPECT_NE(decl, nullptr);
+ EXPECT_EQ(decl->GetComments(), comments);
+ delete decl;
+}
+
+TEST_F(DeclarationTest, Declaration_GetLine) {
+ unsigned line = __LINE__;
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int", ""), params, "", line);
+ EXPECT_NE(decl, nullptr);
+ EXPECT_EQ(decl->GetLine(), line);
+ 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", "")), __LINE__));
+ params->Add(new tidl::Parameter("test2",
+ new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
+ decl = new tidl::Declaration("test",
+ new tidl::BaseType("int", ""), params, "", __LINE__);
+ 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;
+}
+
+TEST_F(DeclarationsTest, Declarations_Exist) {
+ tidl::Declarations* decls = new tidl::Declarations();
+ EXPECT_NE(decls, nullptr);
+ PrepareDeclaration();
+ decls->Add(decl);
+ tidl::Parameters* testParams = new tidl::Parameters();
+ EXPECT_NE(testParams, nullptr);
+ testParams->Add(new tidl::Parameter("test1",
+ new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
+ tidl::Declaration* testDecl = new tidl::Declaration("test",
+ new tidl::BaseType("int", ""), testParams, "", __LINE__);
+ EXPECT_NE(testDecl, nullptr);
+ EXPECT_EQ(decls->Exist(testDecl), true);
+ delete testDecl;
+ 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/ast/document.h"
+#include "idlc/ast/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,
+ "", __LINE__);
+ }
+ 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);
+}
+
+TEST_F(DocumentTest, Document_ExistBlock) {
+ document->AddBlock(block);
+ tidl::Block* testBlock = new tidl::Block("TestBlock",
+ tidl::Block::TYPE_INTERFACE, "", __LINE__);
+ EXPECT_NE(testBlock, nullptr);
+ EXPECT_EQ(document->ExistBlock(testBlock), true);
+ delete testBlock;
+}
--- /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/ast/element.h"
+
+class ElementTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(ElementTest, Element_Contstructor) {
+ tidl::Element* elm = new tidl::Element("test",
+ new tidl::BaseType("int", ""), "", __LINE__);
+ EXPECT_NE(elm, nullptr);
+ delete elm;
+}
+
+TEST_F(ElementTest, Element_GetID) {
+ tidl::Element* elm = new tidl::Element("test",
+ new tidl::BaseType("int", ""), "", __LINE__);
+ EXPECT_NE(elm, nullptr);
+ EXPECT_EQ(elm->GetID(), "test");
+ delete elm;
+}
+
+TEST_F(ElementTest, Element_GetType) {
+ tidl::Element* elm = new tidl::Element("test",
+ new tidl::BaseType("int", ""), "", __LINE__);
+ EXPECT_NE(elm, nullptr);
+ EXPECT_EQ(elm->GetType().ToString(), "int");
+ delete elm;
+}
+
+TEST_F(ElementTest, Element_GetLine) {
+ unsigned line = __LINE__;
+ tidl::Element* elm = new tidl::Element("test",
+ new tidl::BaseType("int", ""), "", line);
+ EXPECT_NE(elm, nullptr);
+ EXPECT_EQ(elm->GetLine(), line);
+ delete elm;
+}
+
+TEST_F(ElementTest, Element_GetComments) {
+ std::string comments = "Test comments";
+ tidl::Element* elm = new tidl::Element("test",
+ new tidl::BaseType("int", ""), comments, __LINE__);
+ EXPECT_NE(elm, nullptr);
+ EXPECT_EQ(elm->GetComments(), comments);
+ delete elm;
+}
+
+class ElementsTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(ElementsTest, Elements_Constructor) {
+ tidl::Elements* elms = new tidl::Elements();
+ EXPECT_NE(elms, nullptr);
+ delete elms;
+}
+
+TEST_F(ElementsTest, Elements_Add) {
+ tidl::Element* elm = new tidl::Element("test",
+ new tidl::BaseType("int", ""), "", __LINE__);
+ EXPECT_NE(elm, nullptr);
+ tidl::Elements* elms = new tidl::Elements();
+ EXPECT_NE(elms, nullptr);
+ elms->Add(elm);
+
+ bool flag = false;
+ for (auto& elm : elms->GetElms()) {
+ if (elm->GetID() == "test" &&
+ elm->GetType().ToString() == "int")
+ flag = true;
+ }
+ EXPECT_EQ(flag, true);
+ delete elms;
+}
+
+TEST_F(ElementsTest, Elements_Getelms) {
+ tidl::Elements* elms = new tidl::Elements();
+ EXPECT_NE(elms, nullptr);
+ elms->Add(new tidl::Element("test1", new tidl::BaseType("int", ""),
+ "", __LINE__));
+ elms->Add(new tidl::Element("test2", new tidl::BaseType("char *", ""),
+ "", __LINE__));
+
+ int count = 0;
+ for (auto& elm : elms->GetElms()) {
+ if (elm->GetID() == "test1" &&
+ elm->GetType().ToString() == "int")
+ count++;
+ if (elm->GetID() == "test2" &&
+ elm->GetType().ToString() == "char *")
+ count++;
+ }
+ EXPECT_EQ(count, 2);
+ delete elms;
+}
+
+TEST_F(ElementsTest, Elements_Exist) {
+ tidl::Element* elm = new tidl::Element("test",
+ new tidl::BaseType("int", ""), "", __LINE__);
+ EXPECT_NE(elm, nullptr);
+ tidl::Elements* elms = new tidl::Elements();
+ EXPECT_NE(elms, nullptr);
+ elms->Add(elm);
+ tidl::Element* elm2 = new tidl::Element("test",
+ new tidl::BaseType("int", ""), "", __LINE__);
+ EXPECT_NE(elm, nullptr);
+ EXPECT_EQ(elms->Exist(elm2), true);
+ delete elm2;
+ delete elms;
+}
--- /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 <memory>
+
+#include "idlc/gen/generator.h"
+#include "idlc/ast/interface.h"
+#include "idlc/ast/structure.h"
+#include "idlc/ast/attribute.h"
+
+class SampleGenerator : public tidl::Generator {
+ public:
+ explicit SampleGenerator(std::shared_ptr<tidl::Document> doc)
+ : tidl::Generator(doc), count_(0) {}
+ ~SampleGenerator() {}
+
+ void OnInitGen(std::ofstream& stream) override {
+ count_++;
+ }
+ void OnFiniGen(std::ofstream& stream) override {
+ count_++;
+ }
+
+ int GetCount() {
+ return count_;
+ }
+
+ private:
+ int count_;
+};
+
+class GeneratorTest : public testing::Test {
+ public:
+ SampleGenerator* gen;
+
+ virtual void SetUp() {
+ gen = new SampleGenerator(
+ std::shared_ptr<tidl::Document>(new tidl::Document()));
+ }
+ virtual void TearDown() {
+ delete gen;
+ }
+};
+
+TEST_F(GeneratorTest, Generator_Constructor) {
+ EXPECT_NE(gen, nullptr);
+}
+
+TEST_F(GeneratorTest, Generator_Run) {
+ EXPECT_NE(gen, nullptr);
+ gen->Run("test.out");
+ EXPECT_EQ(gen->GetCount(), 2);
+}
--- /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/ast/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", "")), __LINE__));
+ params->Add(new tidl::Parameter("test2",
+ new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
+ tidl::Declaration* decl = new tidl::Declaration("test",
+ new tidl::BaseType("int", ""), params, "", __LINE__);
+ 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,
+ "", new tidl::Attributes(), __LINE__);
+ EXPECT_NE(interface, nullptr);
+ delete interface;
+}
+
+TEST_F(InterfaceTest, Interface_GetDeclrations) {
+ tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
+ "", new tidl::Attributes(), __LINE__);
+ 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,
+ "", new tidl::Attributes(), __LINE__);
+ EXPECT_NE(interface, nullptr);
+ EXPECT_EQ(interface->GetID(), "TestInterface");
+ delete interface;
+}
+
+TEST_F(InterfaceTest, Interface_GetType) {
+ tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
+ "", new tidl::Attributes(), __LINE__);
+ EXPECT_NE(interface, nullptr);
+ EXPECT_EQ(interface->GetType(), tidl::Interface::TYPE_INTERFACE);
+ delete interface;
+}
+
+TEST_F(InterfaceTest, Interface_GetLine) {
+ unsigned line = __LINE__;
+ tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
+ "", new tidl::Attributes(), line);
+ EXPECT_NE(interface, nullptr);
+ EXPECT_EQ(interface->GetLine(), line);
+ delete interface;
+}
+
+TEST_F(InterfaceTest, Interface_GetComments) {
+ std::string comments = "Test Interface";
+ tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
+ comments, new tidl::Attributes(), __LINE__);
+ EXPECT_NE(interface, nullptr);
+ EXPECT_EQ(interface->GetComments(), comments);
+ 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 gargc;
+char** gargv;
+
+int main(int argc, char** argv) {
+ gargc = argc;
+ gargv = 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/ast/parser.h"
+
+extern int gargc;
+extern char** gargv;
+
+class ParserTest : public testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(ParserTest, Parser_Constructor) {
+ tidl::Parser* ps = new tidl::Parser();
+ EXPECT_NE(ps, nullptr);
+ delete ps;
+}
+
+TEST_F(ParserTest, Parser_Scanner) {
+ tidl::Parser* ps = new tidl::Parser();
+ EXPECT_NE(ps, nullptr);
+ EXPECT_NE(ps->Scanner(), nullptr);
+ delete ps;
+}
+
+TEST_F(ParserTest, Parser_SetDoc) {
+ tidl::Parser* ps = new tidl::Parser();
+ EXPECT_NE(ps, nullptr);
+ ps->SetDoc(new tidl::Document());
+ EXPECT_NE(ps->GetDoc(), nullptr);
+ delete ps;
+}
+
+TEST_F(ParserTest, Parser_GetDoc) {
+ tidl::Parser* ps = new tidl::Parser();
+ EXPECT_NE(ps, nullptr);
+ ps->SetDoc(new tidl::Document());
+ EXPECT_NE(ps->GetDoc(), nullptr);
+ delete ps;
+}
+
+TEST_F(ParserTest, Parser_Parse) {
+ tidl::Parser* ps = new tidl::Parser();
+ EXPECT_NE(ps, nullptr);
+ std::string input = "interface ParserTest { int test(in int a); }";
+ EXPECT_EQ(ps->Parse(input), true);
+ delete ps;
+}
+
+TEST_F(ParserTest, Parser_ParseFromFile) {
+ tidl::Parser* ps = new tidl::Parser();
+ EXPECT_NE(ps, nullptr);
+
+ std::string file = "test.tidl";
+ if (gargc > 1)
+ file = gargv[1];
+ EXPECT_EQ(ps->ParseFromFile(file), true);
+ delete ps;
+}
+
+TEST_F(ParserTest, Parser_ParseFromFile_N) {
+ tidl::Parser* ps = new tidl::Parser();
+ EXPECT_NE(ps, nullptr);
+
+ std::string file = "test_error.tidl";
+ if (gargc > 2)
+ file = gargv[2];
+ EXPECT_EQ(ps->ParseFromFile(file), false);
+ delete ps;
+}
--- /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/ast/structure.h"
+
+class StructureTest : public testing::Test {
+ public:
+ tidl::Elements* elms;
+
+ virtual void SetUp() {
+ elms = new tidl::Elements();
+ EXPECT_NE(elms, nullptr);
+ elms->Add(new tidl::Element("test1", new tidl::BaseType("int", ""),
+ "", __LINE__));
+ elms->Add(new tidl::Element("test2", new tidl::BaseType("char *", ""),
+ "", __LINE__));
+ }
+ virtual void TearDown() {}
+};
+
+TEST_F(StructureTest, Structure_Constructor) {
+ tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
+ "", __LINE__);
+ EXPECT_NE(structure, nullptr);
+ delete structure;
+}
+
+TEST_F(StructureTest, Structure_GetElements) {
+ tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
+ "", __LINE__);
+ EXPECT_NE(structure, nullptr);
+
+ int count = 0;
+ for (auto& elm : elms->GetElms()) {
+ if (elm->GetID() == "test1" &&
+ elm->GetType().ToString() == "int")
+ count++;
+ if (elm->GetID() == "test2" &&
+ elm->GetType().ToString() == "char *")
+ count++;
+ }
+ EXPECT_EQ(count, 2);
+ delete structure;
+}
+
+TEST_F(StructureTest, Structure_GetID) {
+ tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
+ "", __LINE__);
+ EXPECT_NE(structure, nullptr);
+ EXPECT_EQ(structure->GetID(), "TestStructure");
+ delete structure;
+}
+
+TEST_F(StructureTest, Structure_GetType) {
+ tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
+ "", __LINE__);
+ EXPECT_NE(structure, nullptr);
+ EXPECT_EQ(structure->GetType(), tidl::Structure::TYPE_STRUCTURE);
+ delete structure;
+}
+
+TEST_F(StructureTest, Structure_GetLine) {
+ unsigned line = __LINE__;
+ tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
+ "", line);
+ EXPECT_NE(structure, nullptr);
+ EXPECT_EQ(structure->GetLine(), line);
+ delete structure;
+}
+
+TEST_F(StructureTest, Structure_GetComments) {
+ std::string comments = "Test Structure";
+ tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
+ comments, __LINE__);
+ EXPECT_NE(structure, nullptr);
+ EXPECT_EQ(structure->GetComments(), comments);
+ 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.
+ */
+
+struct Student {
+ string name;
+ int num;
+ bundle data;
+ array<char> tag;
+}
+
+// Annotation Test!!
+// Structure Class
+struct Class {
+ /* string name attr */
+ string name;
+ list<Student> students;
+}
+
+/* Interface School! */
+[privilege = "http://tizen.org/privilege/appmanager.launch", privilege = "http://tizen.org/privilege/appmanager.kill"]
+interface School {
+ /* Method section */
+ /* Method AddClass */
+ int AddClass(in Class cls);
+ /* Method GetStudent */
+ int GetStudent(in string c_name, in string s_name, out Student student);
+ string GetName(out string name);
+ int SetName(in string name);
+}
--- /dev/null
+struct Student {
+ string name;
+ int num;
+ bundle data;
+}
+
+struct Class {
+ string name;
+ list<Student> students;
+}
+
+interface School {
+ int AddClass(in Class cls);
+ int GetStudent(in string c_name, in string s_name, out Student student);
+}
+
+interface School {
+ int RemoveStudent(in string name);
+}
+
+struct {
+ string k;
+}
+
+interface {
+ int test(int a);
+}
+
+struct ErrorAttrMissingName1 {
+ string;
+}
+
+interface ErrorAttrMissingName2 {
+ int (int a);
+}
+
+interface ErrorMethod {
+ void RemoveClass(in class cls);
+}
+
+interface ErrorMethodDupMethod {
+ int GetStudent(in string c_name, out Student student);
+ int GetStudent(in string c_name, out Student student);
+}
+
+struct ErrorMethodDupAttr {
+ string name;
+ string name;
+}
+
+interface ErrorMethodInvalidType {
+ int AddStudent(in string name) async;
+}
--- /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/ast/type.h"
+
+class TokenTest : public testing::Test {
+ public:
+ tidl::Token* testToken;
+
+ virtual void SetUp() {
+ testToken = new tidl::Token("TestToken", "Test Token");
+ }
+ 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");
+}
+
+TEST_F(TokenTest, Token_GetComments) {
+ EXPECT_EQ(testToken->GetComments(), "Test Token");
+}
+
+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_NE(customType->GetMetaType(), nullptr);
+ 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_NE(customType->GetMetaType(), nullptr);
+ 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;
+}
+
+TEST_F(BaseTypeTest, BaseType_GetComments) {
+ std::string comments = "Test BaseType";
+ tidl::BaseType* testType = new tidl::BaseType("TestType", comments, true);
+ EXPECT_NE(testType, nullptr);
+ EXPECT_EQ(testType->GetComments(), comments);
+ 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 clean
+ 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 $SCRIPT_DIR/test.tidl $SCRIPT_DIR/test_error.tidl
+ 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
+++ /dev/null
-LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
-
-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(${GTEST_INCLUDE_DIRS})
-LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS})
-
-SET(TIDLC_SOURCES
- ${CMAKE_SOURCE_DIR}/idlc/ast/document.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/declaration.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/interface.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/type.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/parameter.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/element.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/structure.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/block.cc
- ${CMAKE_SOURCE_DIR}/idlc/gen/generator.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/parser.cc
- ${CMAKE_SOURCE_DIR}/idlc/ast/attribute.cc
- )
-
-ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"")
-
-AUX_SOURCE_DIRECTORY(. UNIT_TESTS_SOURCES)
-AUX_SOURCE_DIRECTORY(cs_gen CS_GEN_UNIT_TESTS_SOURCES)
-AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/idlc/gen CS_GEN_SOURCES)
-
-FLEX_TARGET(TIDLC ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc.ll ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc_l.cpp)
-BISON_TARGET(TIDLC ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc.yy ${CMAKE_SOURCE_DIR}/idlc/ast/tidlc_y.cpp)
-
-ADD_EXECUTABLE(${TIDL_UNIT_TESTS}
- ${BISON_TIDLC_OUTPUTS}
- ${FLEX_TIDLC_OUTPUTS}
- ${TIDLC_SOURCES}
- ${CS_GEN_SOURCES}
- ${UNIT_TESTS_SOURCES}
- ${CS_GEN_UNIT_TESTS_SOURCES}
- )
-TARGET_LINK_LIBRARIES(${TIDL_UNIT_TESTS} ${GTEST_LIBRARIES} pthread)
-
-INSTALL(TARGETS ${TIDL_UNIT_TESTS} DESTINATION bin)
-INSTALL(FILES test.tidl DESTINATION /opt/usr/share/tidl-unit-tests)
-INSTALL(FILES test_error.tidl DESTINATION /opt/usr/share/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/ast/attribute.h"
-
-class AttributeTest : public testing::Test {
- public:
- virtual void SetUp() {}
- virtual void TearDown() {}
-};
-
-TEST_F(AttributeTest, Attribute_Constructor) {
- tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
- EXPECT_NE(attr, nullptr);
- delete attr;
-}
-
-TEST_F(AttributeTest, Attribute_GetKey) {
- tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
- EXPECT_NE(attr, nullptr);
- EXPECT_EQ(attr->GetKey(), "key");
- delete attr;
-}
-
-TEST_F(AttributeTest, Attribute_GetValue) {
- tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
- EXPECT_NE(attr, nullptr);
- EXPECT_EQ(attr->GetValue(), "value");
- delete attr;
-}
-
-TEST_F(AttributeTest, Attribute_GetLine) {
- unsigned line = __LINE__;
- tidl::Attribute* attr = new tidl::Attribute("key", "value", line);
- EXPECT_NE(attr, nullptr);
- EXPECT_EQ(attr->GetLine(), line);
- 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::Attributes* attrs = new tidl::Attributes();
- EXPECT_NE(attrs, nullptr);
- attrs->Add(new tidl::Attribute("key", "value", __LINE__));
-
- bool flag = false;
- for (auto& attr : attrs->GetAttrs()) {
- if (attr->GetKey() == "key" &&
- attr->GetValue() == "value")
- 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("key1", "value1", __LINE__));
- attrs->Add(new tidl::Attribute("key2", "value2", __LINE__));
-
- int count = 0;
- for (auto& attr : attrs->GetAttrs()) {
- if (attr->GetKey() == "key1" &&
- attr->GetValue() == "value1")
- count++;
- if (attr->GetKey() == "key2" &&
- attr->GetValue() == "value2")
- count++;
- }
- EXPECT_EQ(count, 2);
- delete attrs;
-}
-
-TEST_F(AttributesTest, Attributes_Exist) {
- tidl::Attributes* attrs = new tidl::Attributes();
- EXPECT_NE(attrs, nullptr);
- attrs->Add(new tidl::Attribute("key", "value", __LINE__));
- tidl::Attribute* attr = new tidl::Attribute("key", "value", __LINE__);
- EXPECT_NE(attr, nullptr);
- EXPECT_EQ(attrs->Exist(attr), true);
- delete attr;
- 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/ast/block.h"
-
-class BlockTest : public testing::Test {
- public:
- tidl::Block* testBlock;
-
- virtual void SetUp() {
- testBlock = new tidl::Block("TestBlock", tidl::Block::TYPE_INTERFACE,
- "", 28);
- }
- virtual void TearDown() {
- delete testBlock;
- }
-};
-
-TEST_F(BlockTest, Block_Constructor) {
- tidl::Block* block = new tidl::Block("StructureBlock",
- tidl::Block::TYPE_STRUCTURE, "", __LINE__);
- 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);
-}
-
-TEST_F(BlockTest, Block_GetLine) {
- EXPECT_EQ(testBlock->GetLine(), 28);
-}
-
-TEST_F(BlockTest, Block_GetComments) {
- std::string comments = "Test Block";
- tidl::Block* block = new tidl::Block("StructureBlock",
- tidl::Block::TYPE_STRUCTURE, comments, __LINE__);
- EXPECT_NE(block, nullptr);
- EXPECT_EQ(block->GetComments(), comments);
- delete block;
-}
+++ /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/ast/parser.h"
-#include "idlc/gen/cs_proxy_gen.h"
-
-class CsProxyGenTest : public testing::Test {
- public:
- tidl::Parser* ps = nullptr;
-
- virtual void SetUp() {
- ps = new tidl::Parser();
- }
-
- virtual void TearDown() {
- delete ps;
- }
-
- bool FindStringFromFile(std::string filename, std::string str) {
- std::ifstream cb_file(filename);
- std::string line;
-
- while (std::getline(cb_file, line)) {
- if (line.find(str) == 0) {
- return true;
- }
- }
-
- return false;
- }
-};
-
-TEST_F(CsProxyGenTest, CsProxyGen_Constructor) {
- bool ret = ps->ParseFromFile("test.tidl");
- ASSERT_TRUE(ret);
- tidl::CsProxyGen gen(ps->GetDoc());
-}
-
-TEST_F(CsProxyGenTest, CsProxyGen_Run) {
- bool ret = ps->ParseFromFile("test.tidl");
- ASSERT_TRUE(ret);
- tidl::CsProxyGen gen(ps->GetDoc());
- gen.Run("test.cs");
-
- ASSERT_TRUE(FindStringFromFile("test.cs", "namespace RPCPort"));
- ASSERT_TRUE(FindStringFromFile("test.cs",
- " public sealed class Student"));
- ASSERT_TRUE(FindStringFromFile("test.cs",
- " public string name { get; set; }"));
- ASSERT_TRUE(FindStringFromFile("test.cs", " public sealed class Class"));
- ASSERT_TRUE(FindStringFromFile("test.cs",
- " public LinkedList<Student> students { get; set; }"));
-}
+++ /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/ast/parser.h"
-#include "idlc/gen/cs_stub_gen.h"
-
-class CsStubGenTest : public testing::Test {
- public:
- tidl::Parser* ps = nullptr;
-
- virtual void SetUp() {
- ps = new tidl::Parser();
- }
-
- virtual void TearDown() {
- delete ps;
- }
-
- bool FindStringFromFile(std::string filename, std::string str) {
- std::ifstream cb_file(filename);
- std::string line;
-
- while (std::getline(cb_file, line)) {
- if (line.find(str) == 0) {
- return true;
- }
- }
-
- return false;
- }
-};
-
-TEST_F(CsStubGenTest, CsStubGen_Constructor) {
- bool ret = ps->ParseFromFile("test.tidl");
- ASSERT_TRUE(ret);
- tidl::CsStubGen gen(ps->GetDoc());
-}
-
-TEST_F(CsStubGenTest, CsStubGen_Run) {
- bool ret = ps->ParseFromFile("test.tidl");
- ASSERT_TRUE(ret);
- tidl::CsStubGen gen(ps->GetDoc());
- gen.Run("test_stub.cs");
-
- ASSERT_TRUE(FindStringFromFile("test_stub.cs", "namespace RPCPort"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs",
- " public sealed class Student"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs",
- " public string name { get; set; }"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs",
- " public sealed class Class"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs",
- " public LinkedList<Student> students { get; set; }"));
-}
+++ /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/ast/declaration.h"
-#include "idlc/ast/type.h"
-#include "idlc/ast/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", "")), __LINE__));
- params->Add(new tidl::Parameter("test2",
- new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
- }
- virtual void TearDown() {}
-};
-
-TEST_F(DeclarationTest, Declaration_Constructor) {
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", __LINE__);
- EXPECT_NE(decl, nullptr);
- delete decl;
-}
-
-TEST_F(DeclarationTest, Declaration_GetID) {
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", __LINE__);
- 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, "", __LINE__);
- 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, "", __LINE__);
- 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_GetMethodType) {
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", __LINE__,
- tidl::Declaration::MethodType::DELEGATE);
- EXPECT_NE(decl, nullptr);
- EXPECT_EQ(decl->GetMethodType(), tidl::Declaration::MethodType::DELEGATE);
- delete decl;
-}
-
-TEST_F(DeclarationTest, Declaration_GetComments) {
- std::string comments = "Test Declaration";
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, comments, __LINE__);
- EXPECT_NE(decl, nullptr);
- EXPECT_EQ(decl->GetComments(), comments);
- delete decl;
-}
-
-TEST_F(DeclarationTest, Declaration_GetLine) {
- unsigned line = __LINE__;
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", line);
- EXPECT_NE(decl, nullptr);
- EXPECT_EQ(decl->GetLine(), line);
- 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", "")), __LINE__));
- params->Add(new tidl::Parameter("test2",
- new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
- decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", __LINE__);
- 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;
-}
-
-TEST_F(DeclarationsTest, Declarations_Exist) {
- tidl::Declarations* decls = new tidl::Declarations();
- EXPECT_NE(decls, nullptr);
- PrepareDeclaration();
- decls->Add(decl);
- tidl::Parameters* testParams = new tidl::Parameters();
- EXPECT_NE(testParams, nullptr);
- testParams->Add(new tidl::Parameter("test1",
- new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
- tidl::Declaration* testDecl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), testParams, "", __LINE__);
- EXPECT_NE(testDecl, nullptr);
- EXPECT_EQ(decls->Exist(testDecl), true);
- delete testDecl;
- 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/ast/document.h"
-#include "idlc/ast/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,
- "", __LINE__);
- }
- 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);
-}
-
-TEST_F(DocumentTest, Document_ExistBlock) {
- document->AddBlock(block);
- tidl::Block* testBlock = new tidl::Block("TestBlock",
- tidl::Block::TYPE_INTERFACE, "", __LINE__);
- EXPECT_NE(testBlock, nullptr);
- EXPECT_EQ(document->ExistBlock(testBlock), true);
- delete testBlock;
-}
+++ /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/ast/element.h"
-
-class ElementTest : public testing::Test {
- public:
- virtual void SetUp() {}
- virtual void TearDown() {}
-};
-
-TEST_F(ElementTest, Element_Contstructor) {
- tidl::Element* elm = new tidl::Element("test",
- new tidl::BaseType("int", ""), "", __LINE__);
- EXPECT_NE(elm, nullptr);
- delete elm;
-}
-
-TEST_F(ElementTest, Element_GetID) {
- tidl::Element* elm = new tidl::Element("test",
- new tidl::BaseType("int", ""), "", __LINE__);
- EXPECT_NE(elm, nullptr);
- EXPECT_EQ(elm->GetID(), "test");
- delete elm;
-}
-
-TEST_F(ElementTest, Element_GetType) {
- tidl::Element* elm = new tidl::Element("test",
- new tidl::BaseType("int", ""), "", __LINE__);
- EXPECT_NE(elm, nullptr);
- EXPECT_EQ(elm->GetType().ToString(), "int");
- delete elm;
-}
-
-TEST_F(ElementTest, Element_GetLine) {
- unsigned line = __LINE__;
- tidl::Element* elm = new tidl::Element("test",
- new tidl::BaseType("int", ""), "", line);
- EXPECT_NE(elm, nullptr);
- EXPECT_EQ(elm->GetLine(), line);
- delete elm;
-}
-
-TEST_F(ElementTest, Element_GetComments) {
- std::string comments = "Test comments";
- tidl::Element* elm = new tidl::Element("test",
- new tidl::BaseType("int", ""), comments, __LINE__);
- EXPECT_NE(elm, nullptr);
- EXPECT_EQ(elm->GetComments(), comments);
- delete elm;
-}
-
-class ElementsTest : public testing::Test {
- public:
- virtual void SetUp() {}
- virtual void TearDown() {}
-};
-
-TEST_F(ElementsTest, Elements_Constructor) {
- tidl::Elements* elms = new tidl::Elements();
- EXPECT_NE(elms, nullptr);
- delete elms;
-}
-
-TEST_F(ElementsTest, Elements_Add) {
- tidl::Element* elm = new tidl::Element("test",
- new tidl::BaseType("int", ""), "", __LINE__);
- EXPECT_NE(elm, nullptr);
- tidl::Elements* elms = new tidl::Elements();
- EXPECT_NE(elms, nullptr);
- elms->Add(elm);
-
- bool flag = false;
- for (auto& elm : elms->GetElms()) {
- if (elm->GetID() == "test" &&
- elm->GetType().ToString() == "int")
- flag = true;
- }
- EXPECT_EQ(flag, true);
- delete elms;
-}
-
-TEST_F(ElementsTest, Elements_Getelms) {
- tidl::Elements* elms = new tidl::Elements();
- EXPECT_NE(elms, nullptr);
- elms->Add(new tidl::Element("test1", new tidl::BaseType("int", ""),
- "", __LINE__));
- elms->Add(new tidl::Element("test2", new tidl::BaseType("char *", ""),
- "", __LINE__));
-
- int count = 0;
- for (auto& elm : elms->GetElms()) {
- if (elm->GetID() == "test1" &&
- elm->GetType().ToString() == "int")
- count++;
- if (elm->GetID() == "test2" &&
- elm->GetType().ToString() == "char *")
- count++;
- }
- EXPECT_EQ(count, 2);
- delete elms;
-}
-
-TEST_F(ElementsTest, Elements_Exist) {
- tidl::Element* elm = new tidl::Element("test",
- new tidl::BaseType("int", ""), "", __LINE__);
- EXPECT_NE(elm, nullptr);
- tidl::Elements* elms = new tidl::Elements();
- EXPECT_NE(elms, nullptr);
- elms->Add(elm);
- tidl::Element* elm2 = new tidl::Element("test",
- new tidl::BaseType("int", ""), "", __LINE__);
- EXPECT_NE(elm, nullptr);
- EXPECT_EQ(elms->Exist(elm2), true);
- delete elm2;
- delete elms;
-}
+++ /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 <memory>
-
-#include "idlc/gen/generator.h"
-#include "idlc/ast/interface.h"
-#include "idlc/ast/structure.h"
-#include "idlc/ast/attribute.h"
-
-class SampleGenerator : public tidl::Generator {
- public:
- explicit SampleGenerator(std::shared_ptr<tidl::Document> doc)
- : tidl::Generator(doc), count_(0) {}
- ~SampleGenerator() {}
-
- void OnInitGen(std::ofstream& stream) override {
- count_++;
- }
- void OnFiniGen(std::ofstream& stream) override {
- count_++;
- }
-
- int GetCount() {
- return count_;
- }
-
- private:
- int count_;
-};
-
-class GeneratorTest : public testing::Test {
- public:
- SampleGenerator* gen;
-
- virtual void SetUp() {
- gen = new SampleGenerator(
- std::shared_ptr<tidl::Document>(new tidl::Document()));
- }
- virtual void TearDown() {
- delete gen;
- }
-};
-
-TEST_F(GeneratorTest, Generator_Constructor) {
- EXPECT_NE(gen, nullptr);
-}
-
-TEST_F(GeneratorTest, Generator_Run) {
- EXPECT_NE(gen, nullptr);
- gen->Run("test.out");
- EXPECT_EQ(gen->GetCount(), 2);
-}
+++ /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/ast/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", "")), __LINE__));
- params->Add(new tidl::Parameter("test2",
- new tidl::ParameterType(new tidl::BaseType("int", "")), __LINE__));
- tidl::Declaration* decl = new tidl::Declaration("test",
- new tidl::BaseType("int", ""), params, "", __LINE__);
- 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,
- "", new tidl::Attributes(), __LINE__);
- EXPECT_NE(interface, nullptr);
- delete interface;
-}
-
-TEST_F(InterfaceTest, Interface_GetDeclrations) {
- tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- "", new tidl::Attributes(), __LINE__);
- 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,
- "", new tidl::Attributes(), __LINE__);
- EXPECT_NE(interface, nullptr);
- EXPECT_EQ(interface->GetID(), "TestInterface");
- delete interface;
-}
-
-TEST_F(InterfaceTest, Interface_GetType) {
- tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- "", new tidl::Attributes(), __LINE__);
- EXPECT_NE(interface, nullptr);
- EXPECT_EQ(interface->GetType(), tidl::Interface::TYPE_INTERFACE);
- delete interface;
-}
-
-TEST_F(InterfaceTest, Interface_GetLine) {
- unsigned line = __LINE__;
- tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- "", new tidl::Attributes(), line);
- EXPECT_NE(interface, nullptr);
- EXPECT_EQ(interface->GetLine(), line);
- delete interface;
-}
-
-TEST_F(InterfaceTest, Interface_GetComments) {
- std::string comments = "Test Interface";
- tidl::Interface* interface = new tidl::Interface("TestInterface", decls,
- comments, new tidl::Attributes(), __LINE__);
- EXPECT_NE(interface, nullptr);
- EXPECT_EQ(interface->GetComments(), comments);
- 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 gargc;
-char** gargv;
-
-int main(int argc, char** argv) {
- gargc = argc;
- gargv = 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/ast/parser.h"
-
-extern int gargc;
-extern char** gargv;
-
-class ParserTest : public testing::Test {
- public:
- virtual void SetUp() {}
- virtual void TearDown() {}
-};
-
-TEST_F(ParserTest, Parser_Constructor) {
- tidl::Parser* ps = new tidl::Parser();
- EXPECT_NE(ps, nullptr);
- delete ps;
-}
-
-TEST_F(ParserTest, Parser_Scanner) {
- tidl::Parser* ps = new tidl::Parser();
- EXPECT_NE(ps, nullptr);
- EXPECT_NE(ps->Scanner(), nullptr);
- delete ps;
-}
-
-TEST_F(ParserTest, Parser_SetDoc) {
- tidl::Parser* ps = new tidl::Parser();
- EXPECT_NE(ps, nullptr);
- ps->SetDoc(new tidl::Document());
- EXPECT_NE(ps->GetDoc(), nullptr);
- delete ps;
-}
-
-TEST_F(ParserTest, Parser_GetDoc) {
- tidl::Parser* ps = new tidl::Parser();
- EXPECT_NE(ps, nullptr);
- ps->SetDoc(new tidl::Document());
- EXPECT_NE(ps->GetDoc(), nullptr);
- delete ps;
-}
-
-TEST_F(ParserTest, Parser_Parse) {
- tidl::Parser* ps = new tidl::Parser();
- EXPECT_NE(ps, nullptr);
- std::string input = "interface ParserTest { int test(in int a); }";
- EXPECT_EQ(ps->Parse(input), true);
- delete ps;
-}
-
-TEST_F(ParserTest, Parser_ParseFromFile) {
- tidl::Parser* ps = new tidl::Parser();
- EXPECT_NE(ps, nullptr);
-
- std::string file = "test.tidl";
- if (gargc > 1)
- file = gargv[1];
- EXPECT_EQ(ps->ParseFromFile(file), true);
- delete ps;
-}
-
-TEST_F(ParserTest, Parser_ParseFromFile_N) {
- tidl::Parser* ps = new tidl::Parser();
- EXPECT_NE(ps, nullptr);
-
- std::string file = "test_error.tidl";
- if (gargc > 2)
- file = gargv[2];
- EXPECT_EQ(ps->ParseFromFile(file), false);
- delete ps;
-}
+++ /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/ast/structure.h"
-
-class StructureTest : public testing::Test {
- public:
- tidl::Elements* elms;
-
- virtual void SetUp() {
- elms = new tidl::Elements();
- EXPECT_NE(elms, nullptr);
- elms->Add(new tidl::Element("test1", new tidl::BaseType("int", ""),
- "", __LINE__));
- elms->Add(new tidl::Element("test2", new tidl::BaseType("char *", ""),
- "", __LINE__));
- }
- virtual void TearDown() {}
-};
-
-TEST_F(StructureTest, Structure_Constructor) {
- tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
- "", __LINE__);
- EXPECT_NE(structure, nullptr);
- delete structure;
-}
-
-TEST_F(StructureTest, Structure_GetElements) {
- tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
- "", __LINE__);
- EXPECT_NE(structure, nullptr);
-
- int count = 0;
- for (auto& elm : elms->GetElms()) {
- if (elm->GetID() == "test1" &&
- elm->GetType().ToString() == "int")
- count++;
- if (elm->GetID() == "test2" &&
- elm->GetType().ToString() == "char *")
- count++;
- }
- EXPECT_EQ(count, 2);
- delete structure;
-}
-
-TEST_F(StructureTest, Structure_GetID) {
- tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
- "", __LINE__);
- EXPECT_NE(structure, nullptr);
- EXPECT_EQ(structure->GetID(), "TestStructure");
- delete structure;
-}
-
-TEST_F(StructureTest, Structure_GetType) {
- tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
- "", __LINE__);
- EXPECT_NE(structure, nullptr);
- EXPECT_EQ(structure->GetType(), tidl::Structure::TYPE_STRUCTURE);
- delete structure;
-}
-
-TEST_F(StructureTest, Structure_GetLine) {
- unsigned line = __LINE__;
- tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
- "", line);
- EXPECT_NE(structure, nullptr);
- EXPECT_EQ(structure->GetLine(), line);
- delete structure;
-}
-
-TEST_F(StructureTest, Structure_GetComments) {
- std::string comments = "Test Structure";
- tidl::Structure* structure = new tidl::Structure("TestStructure", elms,
- comments, __LINE__);
- EXPECT_NE(structure, nullptr);
- EXPECT_EQ(structure->GetComments(), comments);
- 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.
- */
-
-struct Student {
- string name;
- int num;
- bundle data;
- array<char> tag;
-}
-
-// Annotation Test!!
-// Structure Class
-struct Class {
- /* string name attr */
- string name;
- list<Student> students;
-}
-
-/* Interface School! */
-[privilege = "http://tizen.org/privilege/appmanager.launch", privilege = "http://tizen.org/privilege/appmanager.kill"]
-interface School {
- /* Method section */
- /* Method AddClass */
- int AddClass(in Class cls);
- /* Method GetStudent */
- int GetStudent(in string c_name, in string s_name, out Student student);
- string GetName(out string name);
- int SetName(in string name);
-}
+++ /dev/null
-struct Student {
- string name;
- int num;
- bundle data;
-}
-
-struct Class {
- string name;
- list<Student> students;
-}
-
-interface School {
- int AddClass(in Class cls);
- int GetStudent(in string c_name, in string s_name, out Student student);
-}
-
-interface School {
- int RemoveStudent(in string name);
-}
-
-struct {
- string k;
-}
-
-interface {
- int test(int a);
-}
-
-struct ErrorAttrMissingName1 {
- string;
-}
-
-interface ErrorAttrMissingName2 {
- int (int a);
-}
-
-interface ErrorMethod {
- void RemoveClass(in class cls);
-}
-
-interface ErrorMethodDupMethod {
- int GetStudent(in string c_name, out Student student);
- int GetStudent(in string c_name, out Student student);
-}
-
-struct ErrorMethodDupAttr {
- string name;
- string name;
-}
-
-interface ErrorMethodInvalidType {
- int AddStudent(in string name) async;
-}
+++ /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/ast/type.h"
-
-class TokenTest : public testing::Test {
- public:
- tidl::Token* testToken;
-
- virtual void SetUp() {
- testToken = new tidl::Token("TestToken", "Test Token");
- }
- 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");
-}
-
-TEST_F(TokenTest, Token_GetComments) {
- EXPECT_EQ(testToken->GetComments(), "Test Token");
-}
-
-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_NE(customType->GetMetaType(), nullptr);
- 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_NE(customType->GetMetaType(), nullptr);
- 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;
-}
-
-TEST_F(BaseTypeTest, BaseType_GetComments) {
- std::string comments = "Test BaseType";
- tidl::BaseType* testType = new tidl::BaseType("TestType", comments, true);
- EXPECT_NE(testType, nullptr);
- EXPECT_EQ(testType->GetComments(), comments);
- 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 clean
- 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 $SCRIPT_DIR/test.tidl $SCRIPT_DIR/test_error.tidl
- 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