]>
Commit | Line | Data |
---|---|---|
49e323a5 FM |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/misc/module.cpp | |
3 | // Purpose: Test wxModule | |
4 | // Author: Francesco Montorsi (extracted from console sample) | |
5 | // Created: 2010-06-02 | |
49e323a5 FM |
6 | // Copyright: (c) 2010 wxWidgets team |
7 | /////////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | // ---------------------------------------------------------------------------- | |
10 | // headers | |
11 | // ---------------------------------------------------------------------------- | |
12 | ||
13 | #include "testprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | # pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #include "wx/module.h" | |
8e73dcda | 20 | #include "wx/wxcrt.h" // for wxStrcat() |
49e323a5 FM |
21 | |
22 | // ---------------------------------------------------------------------------- | |
23 | // test classes derived from wxModule | |
24 | // ---------------------------------------------------------------------------- | |
25 | ||
26 | char g_strLoadOrder[256] = "\0"; | |
27 | ||
28 | class Module : public wxModule | |
29 | { | |
30 | protected: | |
31 | virtual bool OnInit() { wxStrcat(g_strLoadOrder, GetClassInfo()->GetClassName()); return true; } | |
32 | virtual void OnExit() { } | |
33 | }; | |
34 | ||
35 | class ModuleA : public Module | |
36 | { | |
37 | public: | |
38 | ModuleA(); | |
39 | private: | |
40 | DECLARE_DYNAMIC_CLASS(ModuleA) | |
41 | }; | |
42 | ||
43 | class ModuleB : public Module | |
44 | { | |
45 | public: | |
46 | ModuleB(); | |
47 | private: | |
48 | DECLARE_DYNAMIC_CLASS(ModuleB) | |
49 | }; | |
50 | ||
51 | class ModuleC : public Module | |
52 | { | |
53 | public: | |
54 | ModuleC(); | |
55 | private: | |
56 | DECLARE_DYNAMIC_CLASS(ModuleC) | |
57 | }; | |
58 | ||
59 | class ModuleD : public Module | |
60 | { | |
61 | public: | |
62 | ModuleD(); | |
63 | private: | |
64 | DECLARE_DYNAMIC_CLASS(ModuleD) | |
65 | }; | |
66 | ||
67 | IMPLEMENT_DYNAMIC_CLASS(ModuleA, wxModule) | |
68 | ModuleA::ModuleA() | |
69 | { | |
70 | AddDependency(CLASSINFO(ModuleB)); | |
71 | AddDependency(CLASSINFO(ModuleD)); | |
72 | } | |
73 | ||
74 | IMPLEMENT_DYNAMIC_CLASS(ModuleB, wxModule) | |
75 | ModuleB::ModuleB() | |
76 | { | |
77 | AddDependency(CLASSINFO(ModuleC)); | |
78 | AddDependency(CLASSINFO(ModuleD)); | |
79 | } | |
80 | ||
81 | IMPLEMENT_DYNAMIC_CLASS(ModuleC, wxModule) | |
82 | ModuleC::ModuleC() | |
83 | { | |
84 | AddDependency(CLASSINFO(ModuleD)); | |
85 | } | |
86 | ||
87 | IMPLEMENT_DYNAMIC_CLASS(ModuleD, wxModule) | |
88 | ModuleD::ModuleD() | |
89 | { | |
90 | } | |
91 | ||
92 | // ---------------------------------------------------------------------------- | |
93 | // test class | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
96 | class ModuleTestCase : public CppUnit::TestCase | |
97 | { | |
98 | public: | |
99 | ModuleTestCase() { } | |
100 | ||
101 | private: | |
102 | CPPUNIT_TEST_SUITE( ModuleTestCase ); | |
103 | CPPUNIT_TEST( LoadOrder ); | |
104 | CPPUNIT_TEST_SUITE_END(); | |
105 | ||
106 | void LoadOrder(); | |
107 | DECLARE_NO_COPY_CLASS(ModuleTestCase) | |
108 | }; | |
109 | ||
110 | // register in the unnamed registry so that these tests are run by default | |
111 | CPPUNIT_TEST_SUITE_REGISTRATION( ModuleTestCase ); | |
112 | ||
e3778b4d | 113 | // also include in its own registry so that these tests can be run alone |
49e323a5 FM |
114 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ModuleTestCase, "ModuleTestCase" ); |
115 | ||
116 | void ModuleTestCase::LoadOrder() | |
117 | { | |
118 | // module D is the only one with no dependencies and so should load as first (and so on): | |
119 | CPPUNIT_ASSERT_EQUAL( "ModuleDModuleCModuleBModuleA", g_strLoadOrder ); | |
120 | } |