From b04339fc03543cbd34b6e9db7adc9eb35caed5c0 Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Fri, 25 May 2018 11:20:12 +0900 Subject: Add unit test Change-Id: Idb7c75c3c9d9b575cee75dc487fe6a7c0548b6ec Signed-off-by: Kazumasa Mitsunari --- deploy.sh | 8 +++ test/CMakeLists.txt | 66 ++++++++++++++++++++ test/applist.cpp | 1 + test/applist.hpp | 1 + test/request.cpp | 1 + test/test.cpp | 139 ++++++++++++++++++++++++++++++++++++++++++ test/windowmanager-client.cpp | 1 + test/windowmanager-client.hpp | 1 + 8 files changed, 218 insertions(+) create mode 100755 deploy.sh create mode 100644 test/CMakeLists.txt create mode 120000 test/applist.cpp create mode 120000 test/applist.hpp create mode 120000 test/request.cpp create mode 100644 test/test.cpp create mode 120000 test/windowmanager-client.cpp create mode 120000 test/windowmanager-client.hpp diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..3c9c0bf --- /dev/null +++ b/deploy.sh @@ -0,0 +1,8 @@ +#!/bin/bash +cd build +source /home/mitsunari/opt/m3ulcb-5.90.0/environment-setup-aarch64-agl-linux +make package +scp package/windowmanager-service-2017.wgt root@192.168.200.17:~ +ssh root@${1} afm-util remove windowmanager-service-2017@0.1 +ssh root@${1} afm-util install windowmanager-service-2017.wgt +ssh root@${1} sync diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..8c693ce --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,66 @@ +# +# Copyright (c) 2017 TOYOTA MOTOR CORPORATION +# +# 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. +# +cmake_minimum_required(VERSION 2.8) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(AFB QUIET afb-daemon) +pkg_check_modules(GT REQUIRED gtest) + +INCLUDE(FindThreads) +FIND_PACKAGE(Threads) + +add_definitions(-DGTEST_ENABLED) + +set(TARGET_TEST wmtest) +set(GTEST_ROOT /home/mitsunari/test/googletest/googletest) + +include_directories(${GTEST_ROOT}/include/) + +link_directories(${GTEST_ROOT}/build/) +add_executable(${TARGET_TEST} + test.cpp + windowmanager-client.cpp + applist.cpp + request.cpp +) + +target_include_directories(${TARGET_TEST} + PRIVATE + ${CMAKE_THREAD_LIBS_INIT} + ${AFB_INCLUDE_DIRS} + ${GT_INCLUDE_DIRS} + ../include + ../src) + +target_link_libraries(${TARGET_TEST} + PRIVATE + ${AFB_LIBRARIES} + ${GT_LIBRARIES} + pthread +) + +set_target_properties(${TARGET_TEST} + PROPERTIES + # INTERPROCEDURAL_OPTIMIZATION ON + + CXX_EXTENSIONS OFF + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + + C_EXTENSIONS OFF + C_STANDARD 99 + C_STANDARD_REQUIRED ON +) diff --git a/test/applist.cpp b/test/applist.cpp new file mode 120000 index 0000000..8e79cbb --- /dev/null +++ b/test/applist.cpp @@ -0,0 +1 @@ +../src/applist.cpp \ No newline at end of file diff --git a/test/applist.hpp b/test/applist.hpp new file mode 120000 index 0000000..a4dd347 --- /dev/null +++ b/test/applist.hpp @@ -0,0 +1 @@ +../src/applist.hpp \ No newline at end of file diff --git a/test/request.cpp b/test/request.cpp new file mode 120000 index 0000000..3069bfe --- /dev/null +++ b/test/request.cpp @@ -0,0 +1 @@ +../src/request.cpp \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..f56cd2f --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,139 @@ +#include +//#include "cpputest/include/CppUTest/CommandLineTestRunner.h" +#include +#include +#include "applist.hpp" +#include "windowmanager-client.hpp" + +// テストグループの定義 TEST_GROUP(group) +// フィクスチャの準備 +using std::cout; +using std::endl; +using std::string; + +namespace +{ + +const string test1 = "testApp"; +const string test2 = "testApp2"; +const string test3 = "testApp3"; +const string test_role = "testRole"; +const string test_area = "testArea"; +const string test1_errname = "testApp_false"; +const string test_role_err = "testRole_false"; +static wm::AppList app_list; + +class dbtest : public ::testing::Test +{ +public: + void SetUp() {} + void TearDown() {} + +protected: +}; + +TEST_F(dbtest, contains) +{ + app_list.addClient(test1, test_role); + bool result = app_list.contains(test1); + EXPECT_EQ(true, result); + result = app_list.contains(test1_errname); + EXPECT_EQ(false, result); +} + +TEST_F(dbtest, lookup) +{ + auto test = app_list.lookUpClient(test1); + cout << "Check getting client object" << endl; + EXPECT_EQ(true, (test) ? true : false); + cout << "Check client name" << endl; + EXPECT_EQ(test1, test->appID()); + cout << "Check exception throwing of out_of_range" << endl; + ASSERT_THROW(app_list.lookUpClient(test1_errname), std::out_of_range); + app_list.client_dump(); +} + +TEST_F(dbtest, remove) +{ + ASSERT_NO_THROW(app_list.removeClient(test1_errname)); + ASSERT_NO_THROW(app_list.removeClient(test1)); + EXPECT_EQ(0, app_list.countClient()); + app_list.addClient(test1, test_role); +} + +class reqtest : public ::testing::Test +{ +public: + void SetUp() {} + void TearDown() {} + +protected: +}; + +TEST_F(reqtest, currentSequenceNumber) +{ + EXPECT_EQ(1, app_list.currentSequenceNumber()); +} + +TEST_F(reqtest, allocate_sequence) +{ + app_list.addClient(test2, test_role); + + wm::WMRequest req1(test1, test_role, test_area, wm::Task::TASK_ALLOCATE); + wm::WMRequest req2(test2, test_role, test_area, wm::Task::TASK_RELEASE); + unsigned seq1 = app_list.addAllocateRequest(req1); + unsigned seq2 = app_list.addAllocateRequest(req2); + + unsigned current = app_list.currentSequenceNumber(); + EXPECT_EQ(1, current); + EXPECT_EQ(1, seq1); + EXPECT_EQ(2, seq2); + + bool result = app_list.requestFinished(); + EXPECT_EQ(false, result); + + result = app_list.setAction(seq1, test1, test_role, test_area); + result &= app_list.setAction(seq1, test3, test_role, test_area); + EXPECT_EQ(true, result); + + app_list.req_dump(); + + result = app_list.setEndDrawFinished(current, test1, test_role); + EXPECT_EQ(true, result); + + result = app_list.endDrawFullfilled(current); + EXPECT_EQ(false, result); + + result = app_list.setEndDrawFinished(current, test3, test_role); + EXPECT_EQ(true, result); + + app_list.req_dump(); + + result = app_list.endDrawFullfilled(current); + EXPECT_EQ(true, result); + + app_list.removeRequest(current); + /* lookup_seq_err = app_list.lookUpAllocatingApp(test1); + EXPECT_EQ(0, lookup_seq_err); */ + + app_list.next(); + unsigned next_seq = app_list.currentSequenceNumber(); + EXPECT_EQ(seq2, next_seq); + result = app_list.haveRequest(); + EXPECT_EQ(true, result); + + app_list.req_dump(); +} + +TEST_F(reqtest, release_sequence) +{ + +} + +} // namespace + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/test/windowmanager-client.cpp b/test/windowmanager-client.cpp new file mode 120000 index 0000000..ae92ca0 --- /dev/null +++ b/test/windowmanager-client.cpp @@ -0,0 +1 @@ +../src/windowmanager-client.cpp \ No newline at end of file diff --git a/test/windowmanager-client.hpp b/test/windowmanager-client.hpp new file mode 120000 index 0000000..a750a64 --- /dev/null +++ b/test/windowmanager-client.hpp @@ -0,0 +1 @@ +../src/windowmanager-client.hpp \ No newline at end of file -- cgit 1.2.3-korg