Skip to content

Commit f23a985

Browse files
author
Jeroen van Iddekinge
committed
* Add test
1 parent 6900a38 commit f23a985

18 files changed

+491
-4
lines changed

CMakeLists.txt

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
cmake_minimum_required(VERSION 2.8.12)
22
project(procgui)
33

4-
set(CMAKE_INCLUDE_CURRENT_DIR ON)
54
set(CMAKE_AUTOMOC ON)
65

76
find_package(ECM REQUIRED NO_MODULE)
87
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
9-
find_package(Qt5Widgets REQUIRED)
8+
9+
10+
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
11+
Core
12+
)
13+
1014
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
1115
CoreAddons
1216
I18n
@@ -42,7 +46,6 @@ set(procgui_LIBS
4246
)
4347

4448
qt5_wrap_ui(procgui_SRC
45-
4649
src/ui/fields.ui
4750
src/ui/procgui.ui
4851
src/ui/procinfodialog.ui
@@ -53,5 +56,9 @@ add_executable(procgui ${procgui_SRC})
5356

5457
target_link_libraries(procgui ${procgui_LIBS})
5558

56-
5759
install(TARGETS procgui DESTINATION bin)
60+
61+
set(RUN_TEST ${run_test})
62+
if(RUN_TEST EQUAL "1")
63+
include("test.cmake")
64+
endif()

test.cmake

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
enable_testing()
2+
3+
message(STATUS "Testing enabled")
4+
set(test_SRCS
5+
test/base/test01.cpp
6+
test/base/run_base.cpp
7+
test/data/cgroup01.cpp
8+
test/data/run_data.cpp
9+
test/lib/testclass.cpp
10+
test/lib/runner.cpp
11+
test/lib/testconfig.cpp
12+
)
13+
14+
add_executable(procgui_test test/test.cpp ${test_SRCS} ${procgui_SRCS})
15+
16+
target_link_libraries(procgui_test
17+
${procgui_LIBS}
18+
${LIB_BLKID}
19+
${LIB_UDEV}
20+
)
21+
22+
23+
install(TARGETS procgui_test ${INSTALL_TARGETS_DEFAULT_ARGS})
24+
add_subdirectory(test)

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ADD_TEST(procgui_test ../procgui_test)

test/base/run_base.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "run_base.h"
2+
#include "test01.h"
3+
4+
class TRunBaseRunner:public TRunner
5+
{
6+
protected:
7+
8+
virtual void doRun()
9+
{
10+
runner(new TTest01());
11+
}
12+
13+
public:
14+
TRunBaseRunner(TTestConfig *p_testConfig):TRunner(p_testConfig)
15+
{
16+
17+
}
18+
19+
};
20+
21+
bool run_base(TTestConfig* p_config)
22+
{
23+
24+
TRunBaseRunner l_run(p_config);
25+
return l_run.run();
26+
}
27+

test/base/run_base.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef __RUN_BASE_H_
2+
#define __RUN_BASE_H_
3+
#include "test/lib/runner.h"
4+
#include "test/lib/testconfig.h"
5+
6+
bool run_base(TTestConfig *p_config);
7+
#endif

test/base/test01.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "test01.h"
2+
#include "test/lib/testclass.h"
3+
/**
4+
* Testing linked list
5+
*/
6+
void TTest01::doRun()
7+
{
8+
test01();
9+
if(getFailed()) return;
10+
test02();
11+
if(getFailed()) return;
12+
test03();
13+
}
14+
15+
void TTest01::test01()
16+
{
17+
if(list->getStart() != nullptr) fail(" getStart is not null");
18+
if(list->getEnd() != nullptr) fail(" End of linklist is not null");
19+
if(list->getLength() != 0) fail(" Length !=0");
20+
if(!list->isEmpty()) fail("isEmopty returns false");
21+
}
22+
23+
24+
void TTest01::test02()
25+
{
26+
item1=new TTestItem(1);
27+
list->append(item1);
28+
if(list->getStart()==nullptr) {
29+
fail(" GetStart is null after append");
30+
return;
31+
}
32+
if(list->getStart() != list->getEnd()){
33+
fail("Start and end not equal after appending one item");
34+
}
35+
if(list->getLength()!= 1){
36+
fail(" length != 1 after appending one item");
37+
return;
38+
}
39+
if(list->getStart()->getItem() != item1){
40+
fail("getItem doesn't return appended item");
41+
return;
42+
}
43+
if(list->getStart()->getItem()->getSomeValue()!=1){
44+
fail(" GetSomeValue !=1");
45+
return;
46+
}
47+
}
48+
49+
50+
void TTest01::test03()
51+
{
52+
item2=new TTestItem(2);
53+
list->append(item2);
54+
if(list->getStart()->getItem() != item1){
55+
fail("After appending second item=>fist item != item1");
56+
}
57+
if(list->getEnd()->getItem() != item2){
58+
fail("After appending second item end 1= item2");
59+
}
60+
if(list->getLength() != 2){
61+
fail("After appending second item length != 2");
62+
}
63+
if(list->isEmpty()){
64+
fail("After appending =>isEmpty returns true");
65+
}
66+
return;
67+
}
68+
69+
TTest01::~TTest01()
70+
{
71+
delete list;
72+
}
73+
74+
TTest01::TTest01()
75+
{
76+
list=new TLinkList<TTestItem>();
77+
}
78+

test/base/test01.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef __TEST01_H_
2+
#define __TEST01_H_
3+
#include "../lib/testclass.h"
4+
#include "../../src/base/linklist.h"
5+
class TTestItem
6+
{
7+
private:
8+
int someValue;
9+
public:
10+
inline int getSomeValue(){ return someValue;}
11+
TTestItem(int p_someValue){ someValue=p_someValue;}
12+
};
13+
14+
class TTest01:public TTestClass
15+
{
16+
private:
17+
TLinkList<TTestItem> *list;
18+
TTestItem *item1=nullptr;
19+
TTestItem *item2=nullptr;
20+
protected:
21+
virtual void doRun() override;
22+
public:
23+
void test01();
24+
void test02();
25+
void test03();
26+
TTest01();
27+
virtual ~TTest01();
28+
};
29+
30+
#endif

test/data/cgroup01.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "cgroup01.h"
2+
#include "src/data/cgroupinfo.h"
3+
4+
TDataCGroup::TDataCGroup():TTestClass()
5+
{
6+
7+
}
8+
9+
TDataCGroup::~TDataCGroup()
10+
{
11+
12+
}
13+
14+
void TDataCGroup::doRun()
15+
{
16+
test01();
17+
}
18+
19+
20+
void TDataCGroup::test01()
21+
{
22+
TCGroupInfo *l_info=new TCGroupInfo(101,"bla1","bla2");
23+
expect("Hyrarchie ID",101,l_info->getHierarchyId());
24+
expect("cgroup","bla2",l_info->getCGroup());
25+
expect("bla2","bla1",l_info->getSubsystems());
26+
}

test/data/cgroup01.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef __CGROUP_H_
2+
#define __CGROUP_H_
3+
#include "test/lib/testclass.h"
4+
5+
class TDataCGroup:public TTestClass{
6+
protected:
7+
virtual void doRun() override;
8+
void test01();
9+
public:
10+
TDataCGroup();
11+
virtual ~TDataCGroup();
12+
};
13+
#endif

test/data/run_data.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "run_data.h"
2+
#include "cgroup01.h"
3+
4+
class TRunDataRunner:public TRunner
5+
{
6+
protected:
7+
8+
virtual void doRun()
9+
{
10+
runner(new TDataCGroup());
11+
}
12+
13+
public:
14+
TRunDataRunner(TTestConfig *p_testConfig):TRunner(p_testConfig)
15+
{
16+
17+
}
18+
19+
};
20+
21+
bool run_data(TTestConfig* p_config)
22+
{
23+
24+
TRunDataRunner l_run(p_config);
25+
return l_run.run();
26+
}

test/data/run_data.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef __RUN_DATA_H_
2+
#define __RUN_DATA_H_
3+
#include "test/lib/runner.h"
4+
#include "test/lib/testconfig.h"
5+
6+
bool run_data(TTestConfig *p_config);
7+
#endif

test/lib/runner.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "runner.h"
2+
#include <iostream>
3+
bool TRunner::run()
4+
{
5+
6+
doRun();
7+
return failed;
8+
}
9+
10+
TRunner::TRunner(TTestConfig* p_config)
11+
{
12+
config=p_config;
13+
}
14+
15+
16+
void TRunner::runner(TTestClass *p_object)
17+
{
18+
p_object->setConfig(config);
19+
if(p_object->run()) failed=true;
20+
delete p_object;
21+
}
22+

test/lib/runner.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __RUNNER_H_
2+
#define __RUNNER_H_
3+
#include "testclass.h"
4+
#include "testconfig.h"
5+
6+
class TRunner
7+
{
8+
private:
9+
bool failed=false;
10+
TTestConfig *config;
11+
protected:
12+
virtual void doRun()=0;
13+
public:
14+
bool run();
15+
void runner(TTestClass *p_object);
16+
TRunner(TTestConfig *p_config);
17+
virtual ~TRunner(){};
18+
};
19+
#endif

0 commit comments

Comments
 (0)