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