[363] | 1 | /*
|
---|
| 2 | * TOPPERS/JSP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Just Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | *
|
---|
| 9 | * ä¸è¨èä½æ¨©è
|
---|
| 10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 11 | * ã«ãã£ã¦å
|
---|
| 12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 15 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 21 | * ç¨ã§ããå½¢ã§åé
|
---|
| 22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 24 | * è
|
---|
| 25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 30 | * ã¨ï¼
|
---|
| 31 | * (a) åé
|
---|
| 32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 34 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 35 | * (b) åé
|
---|
| 36 | å¸ã®å½¢æ
|
---|
| 37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 38 | * å ±åãããã¨ï¼
|
---|
| 39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 40 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 42 | 責ãããã¨ï¼
|
---|
| 43 | *
|
---|
| 44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ã
|
---|
| 46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 49 | *
|
---|
| 50 | * @(#) $Id: collection.cpp,v 1.3 2003/12/15 07:32:13 takayuki Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | // $Header: /home/CVS/configurator/base/collection.cpp,v 1.3 2003/12/15 07:32:13 takayuki Exp $
|
---|
| 54 |
|
---|
| 55 | #include "base/collection.h"
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | using namespace std;
|
---|
| 59 |
|
---|
| 60 | //ç¹ã«ä½ãããªãã³ã³ã¹ãã©ã¯ã¿
|
---|
| 61 | Collection::Collection(void) throw()
|
---|
| 62 | {}
|
---|
| 63 |
|
---|
| 64 | //ãã¹ãã©ã¯ã¿
|
---|
| 65 | Collection::~Collection(void) throw()
|
---|
| 66 | {
|
---|
| 67 | //念ã®ããã«ä¾å¤ã«ãµãããã
|
---|
| 68 | try { clear(); }
|
---|
| 69 | catch(...) {}
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | //ã¤ã³ã¹ã¿ã³ã¹ãã³ã¬ã¯ã·ã§ã³ã«è¿½å (é åºã¯ç»é²é )
|
---|
| 73 | bool Collection::addInstance(Collectable * _instance, bool _destruction) throw()
|
---|
| 74 | {
|
---|
| 75 | bool result = false;
|
---|
| 76 |
|
---|
| 77 | if(isValid() && _instance != 0) {
|
---|
| 78 |
|
---|
| 79 | // åãã¤ã³ã¹ã¿ã³ã¹ã2åç»é²ããªãããã«ãã
|
---|
| 80 | list<Element>::iterator scope;
|
---|
| 81 |
|
---|
| 82 | scope = container.begin();
|
---|
| 83 | while(scope != container.end()) {
|
---|
| 84 | if(scope->instance == _instance)
|
---|
| 85 | break;
|
---|
| 86 | ++ scope;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | if(scope == container.end()) {
|
---|
| 90 | // æ«å°¾ã«è¦ç´ ã追å
|
---|
| 91 | struct Element element;
|
---|
| 92 | element.instance = _instance;
|
---|
| 93 | element.destruction = _destruction;
|
---|
| 94 | container.push_back(element);
|
---|
| 95 | }
|
---|
| 96 | else {
|
---|
| 97 | // ç ´æ£æ示ã¯ææ°ã«ç´ãã¦ãã
|
---|
| 98 | scope->destruction = _destruction;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | result = true;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | return result;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | //æå®ãããCollectableã¤ã³ã¹ã¿ã³ã¹ã«ç¸å½ããå ´æãæãã¤ãã¬ã¼ã¿ã®åå¾ (getInstance)
|
---|
| 108 | list<Collection::Element>::const_iterator Collection::_findInstance(const Collectable * predecessor) const throw()
|
---|
| 109 | {
|
---|
| 110 | list<Element>::const_iterator result;
|
---|
| 111 |
|
---|
| 112 | result = container.begin();
|
---|
| 113 |
|
---|
| 114 | //predecessorãæå®ããã¦ããå ´åã¯æ¢ã
|
---|
| 115 | if(predecessor != 0) {
|
---|
| 116 | while(result != container.end()) {
|
---|
| 117 | if(result->instance == predecessor) {
|
---|
| 118 | ++ result; //æ¤ç´¢ã¯predecessorã®æ¬¡ãã
|
---|
| 119 | break;
|
---|
| 120 | }
|
---|
| 121 | ++ result;
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | return result;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | //ã³ã¬ã¯ã·ã§ã³ããã¤ã³ã¹ã¿ã³ã¹ãåå¾
|
---|
| 129 | Collectable * Collection::getInstance(const type_info & type, const Collectable * predecessor) const throw()
|
---|
| 130 | {
|
---|
| 131 | Collectable * result;
|
---|
| 132 |
|
---|
| 133 | result = 0;
|
---|
| 134 | if(isValid()) {
|
---|
| 135 |
|
---|
| 136 | list<Element>::const_iterator scope;
|
---|
| 137 |
|
---|
| 138 | // å
|
---|
| 139 | è¡ããã¤ã³ã¹ã¿ã³ã¹ã®å ´æãæ¢ã
|
---|
| 140 | scope = _findInstance(predecessor);
|
---|
| 141 |
|
---|
| 142 | // æå®ãããåãæã¤æ¬¡ã®ã¤ã³ã¹ã¿ã³ã¹ãæ¢ã
|
---|
| 143 | while(scope != container.end()) {
|
---|
| 144 | if(typeid(*scope->instance) == type) {
|
---|
| 145 | result = scope->instance;
|
---|
| 146 | break;
|
---|
| 147 | }
|
---|
| 148 | ++ scope;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | return result;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | //ã³ã¬ã¯ã·ã§ã³ããã¤ã³ã¹ã¿ã³ã¹ãé¤å¤ (ç ´æ£ã¯ããªã)
|
---|
| 156 | bool Collection::removeInstance(const Collectable * instance) throw()
|
---|
| 157 | {
|
---|
| 158 | bool result = false;
|
---|
| 159 |
|
---|
| 160 | if(isValid() && instance != 0) {
|
---|
| 161 | list<Element>::iterator scope;
|
---|
| 162 |
|
---|
| 163 | scope = container.begin();
|
---|
| 164 | while(scope != container.end()) {
|
---|
| 165 | if(scope->instance == instance) {
|
---|
| 166 | //è¦ç´ ã®åé¤
|
---|
| 167 | container.erase(scope);
|
---|
| 168 | result = true;
|
---|
| 169 | break;
|
---|
| 170 | }
|
---|
| 171 | ++ scope;
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | return result;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | //å
|
---|
| 179 | ¨è¦ç´ ã®ç ´æ£
|
---|
| 180 | void Collection::clear(void)
|
---|
| 181 | {
|
---|
| 182 | if(isValid()) {
|
---|
| 183 | list<Element>::iterator scope;
|
---|
| 184 | list<Element>::iterator next;
|
---|
| 185 |
|
---|
| 186 | //ç ´æ£ãã©ã°ãã¤ãã¦ããã¤ã³ã¹ã¿ã³ã¹ãç ´æ£
|
---|
| 187 | scope = container.begin();
|
---|
| 188 | while(scope != container.end()) {
|
---|
| 189 |
|
---|
| 190 | next = scope; //ROTç³»ã¯deleteããã¨èªåãæ¶ãã«ãããã®ã§ãã¤ãã¬ã¼ã¿ãä¿åããããã«å
|
---|
| 191 | ã«æ¬¡ãåå¾ãã¦ãã
|
---|
| 192 | ++ next;
|
---|
| 193 |
|
---|
| 194 | if(scope->destruction)
|
---|
| 195 | delete scope->instance;
|
---|
| 196 |
|
---|
| 197 | scope = next;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | container.clear();
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | /************************************************* ãã¹ãã¹ã£ã¼ã *************************************************/
|
---|
| 205 |
|
---|
| 206 | #ifdef TESTSUITE
|
---|
| 207 | #include "coverage_undefs.h"
|
---|
| 208 |
|
---|
| 209 | class TestCollectable : public Collectable
|
---|
| 210 | {};
|
---|
| 211 |
|
---|
| 212 | class TestCollectable2 : public Collectable
|
---|
| 213 | { public: ~TestCollectable2(void) throw() { TestSuite::check("TestCollectable2::~TestCollectable2"); } };
|
---|
| 214 |
|
---|
| 215 | #ifdef _MSC_VER
|
---|
| 216 | class TestCollectable3 : public Collectable
|
---|
| 217 | { public: ~TestCollectable3(void) throw(int) { throw 0; } };
|
---|
| 218 | #endif
|
---|
| 219 |
|
---|
| 220 | class TestCollectable4 : public TestCollectable2
|
---|
| 221 | { public: ~TestCollectable4(void) throw() { TestSuite::check("TestCollectable4::~TestCollectable4"); } };
|
---|
| 222 |
|
---|
| 223 | TESTSUITE(main, Collection)
|
---|
| 224 | {
|
---|
| 225 | BEGIN_CASE("addInstance","addInstance") {
|
---|
| 226 | BEGIN_CASE("1","ã¤ã³ã¹ã¿ã³ã¹ã¯æ£ããç»é²ã§ãã") {
|
---|
| 227 | Collection col;
|
---|
| 228 | TestCollectable test;
|
---|
| 229 | TestCollectable2 test2;
|
---|
| 230 |
|
---|
| 231 | BEGIN_CASE("1","ç»é²ã§ãTRUEãè¿ã (1åç®)") {
|
---|
| 232 | if(!col.addInstance(&test, false))
|
---|
| 233 | TEST_FAIL;
|
---|
| 234 | } END_CASE;
|
---|
| 235 |
|
---|
| 236 | BEGIN_CASE("2","ç»é²ã§ãtrueãè¿ã (2åç®)") {
|
---|
| 237 | if(!col.addInstance(&test2, false))
|
---|
| 238 | TEST_FAIL;
|
---|
| 239 | } END_CASE;
|
---|
| 240 |
|
---|
| 241 | BEGIN_CASE("3","åæ°ãåã£ã¦ã") {
|
---|
| 242 | if(col.container.size() != 2)
|
---|
| 243 | TEST_FAIL;
|
---|
| 244 | } END_CASE;
|
---|
| 245 |
|
---|
| 246 | BEGIN_CASE("4","é çªããã£ã¦ã") {
|
---|
| 247 | list<Element>::iterator scope;
|
---|
| 248 | scope = col.container.begin();
|
---|
| 249 | if(scope->instance != &test || scope->destruction != false)
|
---|
| 250 | TEST_FAIL;
|
---|
| 251 | ++ scope;
|
---|
| 252 | if(scope->instance != &test2 || scope->destruction != false)
|
---|
| 253 | TEST_FAIL;
|
---|
| 254 | ++ scope;
|
---|
| 255 | if(scope != col.container.end())
|
---|
| 256 | TEST_FAIL;
|
---|
| 257 | } END_CASE;
|
---|
| 258 | } END_CASE;
|
---|
| 259 |
|
---|
| 260 | BEGIN_CASE("2","NULLã¤ã³ã¹ã¿ã³ã¹ã¯ç»é²ãããªã") {
|
---|
| 261 | Collection col;
|
---|
| 262 |
|
---|
| 263 | BEGIN_CASE("1","NULLã¤ã³ã¹ã¿ã³ã¹ã渡ãã¨falseãè¿ã") {
|
---|
| 264 | if(col.addInstance(0))
|
---|
| 265 | TEST_FAIL;
|
---|
| 266 | } END_CASE;
|
---|
| 267 |
|
---|
| 268 | BEGIN_CASE("2","ä½ãç»é²ããã¦ããªã") {
|
---|
| 269 | if(col.container.size() != 0)
|
---|
| 270 | TEST_FAIL;
|
---|
| 271 | } END_CASE;
|
---|
| 272 | } END_CASE;
|
---|
| 273 |
|
---|
| 274 | BEGIN_CASE("3","ç¡å¹ãªã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ããæä½ã§falseãè¿ã") {
|
---|
| 275 | Collection col;
|
---|
| 276 |
|
---|
| 277 | if(col.addInstance(0))
|
---|
| 278 | TEST_FAIL;
|
---|
| 279 | } END_CASE;
|
---|
| 280 |
|
---|
| 281 | BEGIN_CASE("4","åä¸ã®ã¤ã³ã¹ã¿ã³ã¹ã2åç»é²ãã¦ã1åã ãããç»é²ãããªã") {
|
---|
| 282 | Collection col;
|
---|
| 283 | TestCollectable test;
|
---|
| 284 |
|
---|
| 285 | TEST_CASE("0","[åæ] ä¸åç®ã¯æ£ããæåãã", col.addInstance(&test, false));
|
---|
| 286 |
|
---|
| 287 | TEST_CASE("1","é¢æ°ã¯æ£ããçµäºãã", col.addInstance(&test, false));
|
---|
| 288 | TEST_CASE("2","ã¤ã³ã¹ã¿ã³ã¹æ°ã¯å¢ãã¦ããªã", col.container.size() == 1);
|
---|
| 289 |
|
---|
| 290 | } END_CASE;
|
---|
| 291 |
|
---|
| 292 | } END_CASE;
|
---|
| 293 |
|
---|
| 294 | BEGIN_CASE("getInstance(type_info)","getInstance(type_info)") {
|
---|
| 295 | Collection col;
|
---|
| 296 | TestCollectable test;
|
---|
| 297 | TestCollectable test_2;
|
---|
| 298 | TestCollectable test_3;
|
---|
| 299 | TestCollectable2 test2;
|
---|
| 300 | TestCollectable2 test2_2;
|
---|
| 301 | TestCollectable2 test2_3;
|
---|
| 302 |
|
---|
| 303 | col.addInstance(test);
|
---|
| 304 | col.addInstance(test2);
|
---|
| 305 | col.addInstance(test_2);
|
---|
| 306 | col.addInstance(test2_2);
|
---|
| 307 | col.addInstance(test_3);
|
---|
| 308 | col.addInstance(test2_3);
|
---|
| 309 |
|
---|
| 310 | Collectable * instance = 0;
|
---|
| 311 |
|
---|
| 312 | BEGIN_CASE("1","æåã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 313 | instance = col.getInstance(typeid(TestCollectable));
|
---|
| 314 | if(instance != &test)
|
---|
| 315 | TEST_FAIL;
|
---|
| 316 | } END_CASE;
|
---|
| 317 |
|
---|
| 318 | BEGIN_CASE("2","次ã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 319 | instance = col.getInstance(typeid(TestCollectable), instance);
|
---|
| 320 | if(instance != &test_2)
|
---|
| 321 | TEST_FAIL;
|
---|
| 322 | } END_CASE;
|
---|
| 323 |
|
---|
| 324 | BEGIN_CASE("3","ããã«æ¬¡ã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 325 | instance = col.getInstance(typeid(TestCollectable), instance);
|
---|
| 326 | if(instance != &test_3)
|
---|
| 327 | TEST_FAIL;
|
---|
| 328 | } END_CASE;
|
---|
| 329 |
|
---|
| 330 | BEGIN_CASE("4","ãã®ã¾ã次ã®è¦ç´ ãåå¾ãããNULLãè¿ã") {
|
---|
| 331 | instance = col.getInstance(typeid(TestCollectable), instance);
|
---|
| 332 | if(instance != 0)
|
---|
| 333 | TEST_FAIL;
|
---|
| 334 | } END_CASE;
|
---|
| 335 |
|
---|
| 336 | BEGIN_CASE("5","æåã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 337 | instance = col.getInstance(typeid(TestCollectable2));
|
---|
| 338 | if(instance != &test2)
|
---|
| 339 | TEST_FAIL;
|
---|
| 340 | } END_CASE;
|
---|
| 341 |
|
---|
| 342 | BEGIN_CASE("6","次ã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 343 | instance = col.getInstance(typeid(TestCollectable2), instance);
|
---|
| 344 | if(instance != &test2_2)
|
---|
| 345 | TEST_FAIL;
|
---|
| 346 | } END_CASE;
|
---|
| 347 |
|
---|
| 348 | BEGIN_CASE("7","ããã«æ¬¡ã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 349 | instance = col.getInstance(typeid(TestCollectable2), instance);
|
---|
| 350 | if(instance != &test2_3)
|
---|
| 351 | TEST_FAIL;
|
---|
| 352 | } END_CASE;
|
---|
| 353 |
|
---|
| 354 | BEGIN_CASE("8","ãã®ã¾ã次ã®è¦ç´ ãåå¾ãããNULLãè¿ã") {
|
---|
| 355 | instance = col.getInstance(typeid(TestCollectable), instance);
|
---|
| 356 | if(instance != 0)
|
---|
| 357 | TEST_FAIL;
|
---|
| 358 | } END_CASE;
|
---|
| 359 |
|
---|
| 360 | BEGIN_CASE("9","åºåºã¯ã©ã¹ã§ã¯ã²ã£ããããªã") {
|
---|
| 361 | instance = col.getInstance(typeid(Collectable));
|
---|
| 362 | if(instance != 0)
|
---|
| 363 | TEST_FAIL;
|
---|
| 364 | } END_CASE;
|
---|
| 365 |
|
---|
| 366 | TEST_CASE("10","NULLã«å¯¾ãã¦å®è¡ããã¨NULLãè¿ã", ((Collection *)0)->getInstance(typeid(Collectable)) == 0);
|
---|
| 367 | } END_CASE;
|
---|
| 368 |
|
---|
| 369 | BEGIN_CASE("getInstance<T>()","getInstance<T>()") {
|
---|
| 370 | Collection col;
|
---|
| 371 | TestCollectable test;
|
---|
| 372 | TestCollectable test_2;
|
---|
| 373 | TestCollectable test_3;
|
---|
| 374 | TestCollectable2 test2;
|
---|
| 375 | TestCollectable2 test2_2;
|
---|
| 376 | TestCollectable2 test2_3;
|
---|
| 377 |
|
---|
| 378 | col.addInstance(test);
|
---|
| 379 | col.addInstance(test2);
|
---|
| 380 | col.addInstance(test_2);
|
---|
| 381 | col.addInstance(test2_2);
|
---|
| 382 | col.addInstance(test_3);
|
---|
| 383 | col.addInstance(test2_3);
|
---|
| 384 |
|
---|
| 385 | Collectable * instance = 0;
|
---|
| 386 |
|
---|
| 387 | BEGIN_CASE("1","æåã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 388 | instance = col.getInstance<TestCollectable>();
|
---|
| 389 | if(instance != &test)
|
---|
| 390 | TEST_FAIL;
|
---|
| 391 | } END_CASE;
|
---|
| 392 |
|
---|
| 393 | BEGIN_CASE("2","次ã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 394 | instance = col.getInstance<TestCollectable>(instance);
|
---|
| 395 | if(instance != &test_2)
|
---|
| 396 | TEST_FAIL;
|
---|
| 397 | } END_CASE;
|
---|
| 398 |
|
---|
| 399 | BEGIN_CASE("3","ããã«æ¬¡ã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 400 | instance = col.getInstance<TestCollectable>(instance);
|
---|
| 401 | if(instance != &test_3)
|
---|
| 402 | TEST_FAIL;
|
---|
| 403 | } END_CASE;
|
---|
| 404 |
|
---|
| 405 | BEGIN_CASE("4","ãã®ã¾ã次ã®è¦ç´ ãåå¾ãããNULLãè¿ã") {
|
---|
| 406 | instance = col.getInstance<TestCollectable>(instance);
|
---|
| 407 | if(instance != 0)
|
---|
| 408 | TEST_FAIL;
|
---|
| 409 | } END_CASE;
|
---|
| 410 |
|
---|
| 411 | BEGIN_CASE("5","æåã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 412 | instance = col.getInstance<TestCollectable2>();
|
---|
| 413 | if(instance != &test2)
|
---|
| 414 | TEST_FAIL;
|
---|
| 415 | } END_CASE;
|
---|
| 416 |
|
---|
| 417 | BEGIN_CASE("6","次ã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 418 | instance = col.getInstance<TestCollectable2>(instance);
|
---|
| 419 | if(instance != &test2_2)
|
---|
| 420 | TEST_FAIL;
|
---|
| 421 | } END_CASE;
|
---|
| 422 |
|
---|
| 423 | BEGIN_CASE("7","ããã«æ¬¡ã®è¦ç´ ãåå¾ã§ãã") {
|
---|
| 424 | instance = col.getInstance<TestCollectable2>(instance);
|
---|
| 425 | if(instance != &test2_3)
|
---|
| 426 | TEST_FAIL;
|
---|
| 427 | } END_CASE;
|
---|
| 428 |
|
---|
| 429 | BEGIN_CASE("8","ãã®ã¾ã次ã®è¦ç´ ãåå¾ãããNULLãè¿ã") {
|
---|
| 430 | instance = col.getInstance<TestCollectable2>(instance);
|
---|
| 431 | if(instance != 0)
|
---|
| 432 | TEST_FAIL;
|
---|
| 433 | } END_CASE;
|
---|
| 434 |
|
---|
| 435 | BEGIN_CASE("9","åºåºã¯ã©ã¹ã§å¼ã£æãã ãã®1") {
|
---|
| 436 | instance = col.getInstance<Collectable>();
|
---|
| 437 | if(instance != &test)
|
---|
| 438 | TEST_FAIL;
|
---|
| 439 | } END_CASE;
|
---|
| 440 |
|
---|
| 441 | BEGIN_CASE("10","åºåºã¯ã©ã¹ã§å¼ã£æãã ãã®2") {
|
---|
| 442 | instance = col.getInstance<Collectable>(instance);
|
---|
| 443 | if(instance != &test2)
|
---|
| 444 | TEST_FAIL;
|
---|
| 445 | } END_CASE;
|
---|
| 446 |
|
---|
| 447 | BEGIN_CASE("11","åºåºã¯ã©ã¹ã§å¼ã£æãã ãã®3") {
|
---|
| 448 | instance = col.getInstance<Collectable>(instance);
|
---|
| 449 | if(instance != &test_2)
|
---|
| 450 | TEST_FAIL;
|
---|
| 451 | } END_CASE;
|
---|
| 452 |
|
---|
| 453 | BEGIN_CASE("12","åºåºã¯ã©ã¹ã§å¼ã£æãã ãã®4") {
|
---|
| 454 | instance = col.getInstance<Collectable>(instance);
|
---|
| 455 | if(instance != &test2_2)
|
---|
| 456 | TEST_FAIL;
|
---|
| 457 | } END_CASE;
|
---|
| 458 |
|
---|
| 459 | BEGIN_CASE("13","åºåºã¯ã©ã¹ã§å¼ã£æãã ãã®5") {
|
---|
| 460 | instance = col.getInstance<Collectable>(instance);
|
---|
| 461 | if(instance != &test_3)
|
---|
| 462 | TEST_FAIL;
|
---|
| 463 | } END_CASE;
|
---|
| 464 |
|
---|
| 465 | BEGIN_CASE("14","åºåºã¯ã©ã¹ã§å¼ã£æãã ãã®6") {
|
---|
| 466 | instance = col.getInstance<Collectable>(instance);
|
---|
| 467 | if(instance != &test2_3)
|
---|
| 468 | TEST_FAIL;
|
---|
| 469 | } END_CASE;
|
---|
| 470 |
|
---|
| 471 | BEGIN_CASE("15","åºåºã¯ã©ã¹ã§å¼ã£æãã ãã®7") {
|
---|
| 472 | instance = col.getInstance<Collectable>(instance);
|
---|
| 473 | if(instance != 0)
|
---|
| 474 | TEST_FAIL;
|
---|
| 475 | } END_CASE;
|
---|
| 476 |
|
---|
| 477 | TEST_CASE("16","NULLã«å¯¾ãã¦å®è¡ããã¨NULLãè¿ã", ((Collection *)0)->getInstance<Collectable>() == 0);
|
---|
| 478 |
|
---|
| 479 | } END_CASE;
|
---|
| 480 |
|
---|
| 481 | BEGIN_CASE("removeInstance","removeInstance") {
|
---|
| 482 |
|
---|
| 483 | BEGIN_CASE("1","æ£å¸¸ã«åé¤ã§ãã") {
|
---|
| 484 | Collection col;
|
---|
| 485 | TestCollectable test;
|
---|
| 486 | TestCollectable test2;
|
---|
| 487 |
|
---|
| 488 | col.addInstance(test);
|
---|
| 489 | col.addInstance(test2);
|
---|
| 490 |
|
---|
| 491 | BEGIN_CASE("1","åå¨ããè¦ç´ ãremoveãããtrue") {
|
---|
| 492 | if(!col.removeInstance(&test))
|
---|
| 493 | TEST_FAIL;
|
---|
| 494 | } END_CASE;
|
---|
| 495 |
|
---|
| 496 | BEGIN_CASE("2","ã¡ããã¨æ¶ãã¦ãã") {
|
---|
| 497 | if(col.container.size() != 1 || col.container.begin()->instance != &test2)
|
---|
| 498 | TEST_FAIL;
|
---|
| 499 | } END_CASE;
|
---|
| 500 | } END_CASE;
|
---|
| 501 |
|
---|
| 502 | BEGIN_CASE("2","NULLã¤ã³ã¹ã¿ã³ã¹ã«å®è¡ããã¨false") {
|
---|
| 503 | if(((Collection *)0)->removeInstance(0))
|
---|
| 504 | TEST_FAIL;
|
---|
| 505 | } END_CASE;
|
---|
| 506 |
|
---|
| 507 | BEGIN_CASE("3","ç»é²ãã¦ããªãã¤ã³ã¹ã¿ã³ã¹ãæå®ããã¨å¤±æãã") {
|
---|
| 508 | Collection col;
|
---|
| 509 | TestCollectable test;
|
---|
| 510 | TestCollectable test2;
|
---|
| 511 |
|
---|
| 512 | col.addInstance(test);
|
---|
| 513 |
|
---|
| 514 | if(col.removeInstance(&test2))
|
---|
| 515 | TEST_FAIL;
|
---|
| 516 | } END_CASE;
|
---|
| 517 |
|
---|
| 518 | BEGIN_CASE("4","NULLã¤ã³ã¹ã¿ã³ã¹ã渡ãã¨å¤±æãã") {
|
---|
| 519 | Collection col;
|
---|
| 520 | TestCollectable test;
|
---|
| 521 | col.addInstance(test);
|
---|
| 522 |
|
---|
| 523 | if(col.removeInstance(0))
|
---|
| 524 | TEST_FAIL;
|
---|
| 525 | } END_CASE;
|
---|
| 526 | } END_CASE;
|
---|
| 527 |
|
---|
| 528 | BEGIN_CASE("clear","clear") {
|
---|
| 529 | BEGIN_CASE("1","å®ä½ãç»é²ãã¦clear") {
|
---|
| 530 | Collection col;
|
---|
| 531 | TestCollectable2 test2;
|
---|
| 532 |
|
---|
| 533 | TestSuite::clearCheckpoints();
|
---|
| 534 | col.addInstance(test2);
|
---|
| 535 | col.clear();
|
---|
| 536 |
|
---|
| 537 | BEGIN_CASE("1","è¦ç´ ããªããªã£ã¦ãã") {
|
---|
| 538 | if(col.container.size() != 0)
|
---|
| 539 | TEST_FAIL;
|
---|
| 540 | } END_CASE;
|
---|
| 541 |
|
---|
| 542 | TEST_CASE("2","test2ã¯ç ´æ£ãããªã", !TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 543 | } END_CASE;
|
---|
| 544 |
|
---|
| 545 | BEGIN_CASE("2","ãã¤ã³ã¿ãç»é²ãã¦clear") {
|
---|
| 546 | Collection col;
|
---|
| 547 | TestCollectable2 * test2 = new TestCollectable2;
|
---|
| 548 |
|
---|
| 549 | TestSuite::clearCheckpoints();
|
---|
| 550 | col.addInstance(test2);
|
---|
| 551 | col.clear();
|
---|
| 552 |
|
---|
| 553 | BEGIN_CASE("1","è¦ç´ ããªããªã£ã¦ãã") {
|
---|
| 554 | if(col.container.size() != 0)
|
---|
| 555 | TEST_FAIL;
|
---|
| 556 | } END_CASE;
|
---|
| 557 |
|
---|
| 558 | TEST_CASE("2","test2ã¯ç ´æ£ããã", TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 559 | } END_CASE;
|
---|
| 560 |
|
---|
| 561 | BEGIN_CASE("3","NULLãªãã¸ã§ã¯ãã«å¯¾ãã¦å®è¡ãã¦ãæ´èµ°ããªã") {
|
---|
| 562 | ((Collection *)0)->clear();
|
---|
| 563 | } END_CASE;
|
---|
| 564 |
|
---|
| 565 | #ifdef _MSC_VER
|
---|
| 566 | BEGIN_CASE("4","ä¾å¤ãåºããããªãã¹ãã©ã¯ã¿ããã¤ã¤ã³ã¹ã¿ã³ã¹ãç ´æ£ããã¨ä¾å¤ãæ¼ãã") {
|
---|
| 567 | Collection col;
|
---|
| 568 | bool result = false;
|
---|
| 569 | TestCollectable3 * test = new TestCollectable3;
|
---|
| 570 |
|
---|
| 571 | col.addInstance(test);
|
---|
| 572 | try {
|
---|
| 573 | col.clear();
|
---|
| 574 | }
|
---|
| 575 | catch(...) {
|
---|
| 576 | result = true;
|
---|
| 577 | }
|
---|
| 578 |
|
---|
| 579 |
|
---|
| 580 | if(!result)
|
---|
| 581 | TEST_FAIL;
|
---|
| 582 | } END_CASE;
|
---|
| 583 | #endif
|
---|
| 584 | } END_CASE;
|
---|
| 585 |
|
---|
| 586 | BEGIN_CASE("destructor","destructor") {
|
---|
| 587 | BEGIN_CASE("1","å®ä½ãç»é²ãã¦ç ´æ£") {
|
---|
| 588 | Collection * col = new Collection;
|
---|
| 589 | TestCollectable2 test2;
|
---|
| 590 |
|
---|
| 591 | TestSuite::clearCheckpoints();
|
---|
| 592 | col->addInstance(test2);
|
---|
| 593 | delete col;
|
---|
| 594 |
|
---|
| 595 | TEST_CASE("1","test2ã¯ç ´æ£ãããªã", !TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 596 | } END_CASE;
|
---|
| 597 |
|
---|
| 598 | BEGIN_CASE("2","ãã¤ã³ã¿ãç»é²ãã¦clear") {
|
---|
| 599 | Collection * col = new Collection;
|
---|
| 600 | TestCollectable2 * test2 = new TestCollectable2;
|
---|
| 601 |
|
---|
| 602 | TestSuite::clearCheckpoints();
|
---|
| 603 | col->addInstance(test2);
|
---|
| 604 | delete col;
|
---|
| 605 |
|
---|
| 606 | TEST_CASE("1","test2ã¯ç ´æ£ããã", TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 607 | } END_CASE;
|
---|
| 608 |
|
---|
| 609 | #ifdef _MSC_VER
|
---|
| 610 | BEGIN_CASE("3","ä¾å¤ãåºããããªãã¹ãã©ã¯ã¿ãæã¤ã¤ã³ã¹ã¿ã³ã¹ãç ´æ£ãã¦ãä¾å¤ãæ¼ããªã") {
|
---|
| 611 | Collection * col = new Collection;
|
---|
| 612 | TestCollectable3 * test2 = new TestCollectable3;
|
---|
| 613 | bool result = true;
|
---|
| 614 |
|
---|
| 615 | TestSuite::clearCheckpoints();
|
---|
| 616 | col->addInstance(test2);
|
---|
| 617 |
|
---|
| 618 | try {
|
---|
| 619 | delete col;
|
---|
| 620 | }
|
---|
| 621 | catch(...) {
|
---|
| 622 | result = false;
|
---|
| 623 | }
|
---|
| 624 |
|
---|
| 625 | if(!result)
|
---|
| 626 | TEST_FAIL;
|
---|
| 627 | } END_CASE;
|
---|
| 628 | #endif
|
---|
| 629 | } END_CASE;
|
---|
| 630 |
|
---|
| 631 | BEGIN_CASE("deleteInstance","deleteInstance") {
|
---|
| 632 | BEGIN_CASE("1","ã¤ã³ã¹ã¿ã³ã¹ãåé¤ã§ãã") {
|
---|
| 633 | Collection col;
|
---|
| 634 | TestCollectable2 * test = new TestCollectable2;
|
---|
| 635 |
|
---|
| 636 | TestSuite::clearCheckpoints();
|
---|
| 637 | col.addInstance(test);
|
---|
| 638 |
|
---|
| 639 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance<TestCollectable2>() != 0);
|
---|
| 640 |
|
---|
| 641 | col.deleteInstance<TestCollectable2>();
|
---|
| 642 | TEST_CASE("1","ã¤ã³ã¹ã¿ã³ã¹ãæ¶ãã¦ãã", col.getInstance<TestCollectable2>() == 0);
|
---|
| 643 | TEST_CASE("2","ãã¹ãã©ã¯ã¿ãå®è¡ããã¦ãã", TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 644 | }END_CASE;
|
---|
| 645 |
|
---|
| 646 | BEGIN_CASE("2","é¢ä¿ãªãã¯ã©ã¹ãæå®ãããåé¤ãããªã") {
|
---|
| 647 | Collection col;
|
---|
| 648 | TestCollectable2 * test = new TestCollectable2;
|
---|
| 649 |
|
---|
| 650 | TestSuite::clearCheckpoints();
|
---|
| 651 | col.addInstance(test);
|
---|
| 652 |
|
---|
| 653 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance<TestCollectable2>() != 0);
|
---|
| 654 |
|
---|
| 655 | col.deleteInstance<TestCollectable>();
|
---|
| 656 | TEST_CASE("1","ã¤ã³ã¹ã¿ã³ã¹ãæ¶ãã¦ããªã", col.getInstance<TestCollectable2>() != 0);
|
---|
| 657 | TEST_CASE("2","ãã¹ãã©ã¯ã¿ãå®è¡ããã¦ããªã", !TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 658 | delete test;
|
---|
| 659 | }END_CASE;
|
---|
| 660 |
|
---|
| 661 | BEGIN_CASE("3","åãã¯ã©ã¹ã ãã§ãªãæ´¾çå
|
---|
| 662 | ãæ¶ãã") {
|
---|
| 663 | Collection col;
|
---|
| 664 | TestCollectable2 * test = new TestCollectable2;
|
---|
| 665 | TestCollectable4 * test2 = new TestCollectable4;
|
---|
| 666 |
|
---|
| 667 | TestSuite::clearCheckpoints();
|
---|
| 668 | col.addInstance(test);
|
---|
| 669 | col.addInstance(test2);
|
---|
| 670 |
|
---|
| 671 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance(typeid(TestCollectable2)) != 0);
|
---|
| 672 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance(typeid(TestCollectable4)) != 0);
|
---|
| 673 |
|
---|
| 674 | col.deleteInstance<TestCollectable2>();
|
---|
| 675 | TEST_CASE("1","ã¤ã³ã¹ã¿ã³ã¹ããã¹ã¦æ¶ãã¦ãã", col.getInstance<TestCollectable2>() == 0);
|
---|
| 676 | TEST_CASE("2","TestCollectable2ã®ãã¹ãã©ã¯ã¿ãå®è¡ããã¦ãã", TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 677 | TEST_CASE("3","TestCollectable4ã®ãã¹ãã©ã¯ã¿ãå®è¡ããã¦ãã", TestSuite::isReached("TestCollectable4::~TestCollectable4"));
|
---|
| 678 | }END_CASE;
|
---|
| 679 |
|
---|
| 680 | BEGIN_CASE("4","å®ä½ã¯ç ´æ£å¯¾è±¡ã«ãªããªã") {
|
---|
| 681 | Collection col;
|
---|
| 682 | TestCollectable2 test;
|
---|
| 683 |
|
---|
| 684 | TestSuite::clearCheckpoints();
|
---|
| 685 | col.addInstance(test);
|
---|
| 686 |
|
---|
| 687 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance<TestCollectable2>() != 0);
|
---|
| 688 |
|
---|
| 689 | col.deleteInstance<TestCollectable2>();
|
---|
| 690 | TEST_CASE("1","ã¤ã³ã¹ã¿ã³ã¹ãæ¶ãã¦ãã", col.getInstance<TestCollectable2>() == 0);
|
---|
| 691 | TEST_CASE("2","ãã¹ãã©ã¯ã¿ãå®è¡ããã¦ããªã", !TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 692 | }END_CASE;
|
---|
| 693 |
|
---|
| 694 | BEGIN_CASE("5","NULLãªãã¸ã§ã¯ãã«å¯¾ãã¦çºè¡ãã¦ãæ´èµ°ããªã") {
|
---|
| 695 | ((Collection *)0)->deleteInstance<TestCollectable>();
|
---|
| 696 | } END_CASE;
|
---|
| 697 |
|
---|
| 698 | } END_CASE;
|
---|
| 699 |
|
---|
| 700 | BEGIN_CASE("replaceInstance","replaceInstance") {
|
---|
| 701 | BEGIN_CASE("1","ç»é²æ¸ã¿ã®ã¤ã³ã¹ã¿ã³ã¹ãå
|
---|
| 702 | ¥ãæ¿ãã") {
|
---|
| 703 | Collection col;
|
---|
| 704 | TestCollectable2 test;
|
---|
| 705 | TestCollectable2 test2;
|
---|
| 706 |
|
---|
| 707 | TestSuite::clearCheckpoints();
|
---|
| 708 | col.addInstance(test);
|
---|
| 709 |
|
---|
| 710 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance(typeid(TestCollectable2)) != 0);
|
---|
| 711 |
|
---|
| 712 | TEST_CASE("1", "é¢æ°ã¯æåãã", col.replaceInstance<TestCollectable2>(test2));
|
---|
| 713 | TEST_CASE("2", "ã¤ã³ã¹ã¿ã³ã¹ã¯å
|
---|
| 714 | ¥ãæ¿ãã£ã¦ãã", col.getInstance(typeid(TestCollectable2)) == &test2);
|
---|
| 715 | TEST_CASE("3", "test2以å¤ã«ã¤ã³ã¹ã¿ã³ã¹ã¯ãªã", col.getInstance(typeid(TestCollectable2), &test2) == 0);
|
---|
| 716 | TEST_CASE("4", "ãã¹ãã©ã¯ã¿ã¯å®è¡ããã¦ãªã", !TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 717 | } END_CASE;
|
---|
| 718 |
|
---|
| 719 | BEGIN_CASE("2","ç»é²æ¸ã¿ã®ã¤ã³ã¹ã¿ã³ã¹ãæ´¾çã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã§å
|
---|
| 720 | ¥ãæ¿ãã") {
|
---|
| 721 | Collection col;
|
---|
| 722 | TestCollectable2 test;
|
---|
| 723 | TestCollectable4 test2;
|
---|
| 724 |
|
---|
| 725 | TestSuite::clearCheckpoints();
|
---|
| 726 | col.addInstance(test);
|
---|
| 727 |
|
---|
| 728 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance(typeid(TestCollectable2)) != 0);
|
---|
| 729 |
|
---|
| 730 | TEST_CASE("1", "é¢æ°ã¯æåãã", col.replaceInstance<TestCollectable2>(test2));
|
---|
| 731 | TEST_CASE("2", "ã¤ã³ã¹ã¿ã³ã¹ã¯å
|
---|
| 732 | ¥ãæ¿ãã£ã¦ãã", col.getInstance<TestCollectable2>() == &test2);
|
---|
| 733 | TEST_CASE("3", "test2以å¤ã«ã¤ã³ã¹ã¿ã³ã¹ã¯ãªã", col.getInstance(typeid(TestCollectable2)) == 0);
|
---|
| 734 | TEST_CASE("4", "ãã¹ãã©ã¯ã¿ã¯å®è¡ããã¦ãªã", !TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 735 | } END_CASE;
|
---|
| 736 |
|
---|
| 737 | BEGIN_CASE("3","ç¡é¢ä¿ãªã¯ã©ã¹ãæå®ãã¦å
|
---|
| 738 | ¥ãæ¿ãã") {
|
---|
| 739 | Collection col;
|
---|
| 740 | TestCollectable2 test;
|
---|
| 741 | TestCollectable4 test2;
|
---|
| 742 |
|
---|
| 743 | TestSuite::clearCheckpoints();
|
---|
| 744 | col.addInstance(test);
|
---|
| 745 |
|
---|
| 746 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance(typeid(TestCollectable2)) != 0);
|
---|
| 747 |
|
---|
| 748 | TEST_CASE("1", "é¢æ°ã¯å¤±æãã", !col.replaceInstance<TestCollectable>(test2));
|
---|
| 749 | TEST_CASE("2", "ã¤ã³ã¹ã¿ã³ã¹ã¯æ®ã£ã¦ãã", col.getInstance<TestCollectable2>() == &test);
|
---|
| 750 | } END_CASE;
|
---|
| 751 |
|
---|
| 752 | BEGIN_CASE("4","ç»é²æ¸ã¿ã®ã¤ã³ã¹ã¿ã³ã¹ãå
|
---|
| 753 | ¥ãæ¿ãã (åç確ä¿)") {
|
---|
| 754 | Collection col;
|
---|
| 755 | TestCollectable2 * test = new TestCollectable2;
|
---|
| 756 | TestCollectable2 test2;
|
---|
| 757 |
|
---|
| 758 | TestSuite::clearCheckpoints();
|
---|
| 759 | col.addInstance(test);
|
---|
| 760 |
|
---|
| 761 | TEST_CASE("0","[åæ] ã¡ããã¨ç»é²ããã¦ãã", col.getInstance(typeid(TestCollectable2)) != 0);
|
---|
| 762 |
|
---|
| 763 | TEST_CASE("1", "é¢æ°ã¯æåãã", col.replaceInstance<TestCollectable2>(test2));
|
---|
| 764 | TEST_CASE("2", "ã¤ã³ã¹ã¿ã³ã¹ã¯å
|
---|
| 765 | ¥ãæ¿ãã£ã¦ãã", col.getInstance(typeid(TestCollectable2)) == &test2);
|
---|
| 766 | TEST_CASE("3", "test2以å¤ã«ã¤ã³ã¹ã¿ã³ã¹ã¯ãªã", col.getInstance(typeid(TestCollectable2), &test2) == 0);
|
---|
| 767 | TEST_CASE("4", "ãã¹ãã©ã¯ã¿ã¯å®è¡ããã¦ã", TestSuite::isReached("TestCollectable2::~TestCollectable2"));
|
---|
| 768 | } END_CASE;
|
---|
| 769 |
|
---|
| 770 | } END_CASE;
|
---|
| 771 | }
|
---|
| 772 |
|
---|
| 773 |
|
---|
| 774 | class TestRuntimeObject : public RuntimeObject
|
---|
| 775 | {
|
---|
| 776 | public:
|
---|
| 777 | TestRuntimeObject(void) { CHECKPOINT("TestRuntimeObject::TestRuntimeObject"); }
|
---|
| 778 | ~TestRuntimeObject(void) { CHECKPOINT("TestRuntimeObject::~TestRuntimeObject"); }
|
---|
| 779 | };
|
---|
| 780 |
|
---|
| 781 | class TestRuntimeObject2 : public RuntimeObject
|
---|
| 782 | {
|
---|
| 783 | public:
|
---|
| 784 | TestRuntimeObject2(void) : RuntimeObject(true) { CHECKPOINT("TestRuntimeObject2::TestRuntimeObject2"); }
|
---|
| 785 | ~TestRuntimeObject2(void) { CHECKPOINT("TestRuntimeObject2::~TestRuntimeObject2"); }
|
---|
| 786 | };
|
---|
| 787 |
|
---|
| 788 | TESTSUITE(main, RuntimeObjectTable)
|
---|
| 789 | {
|
---|
| 790 | Singleton<RuntimeObjectTable>::Context context;
|
---|
| 791 | Singleton<RuntimeObjectTable>::saveContext(context);
|
---|
| 792 |
|
---|
| 793 | BEGIN_CASE("getInstance","getInstance") {
|
---|
| 794 | BEGIN_CASE("1","getInstanceã¯æ£ããæ©è½ãã") {
|
---|
| 795 | Singleton<RuntimeObjectTable>::renewInstance();
|
---|
| 796 | TestCollectable test;
|
---|
| 797 |
|
---|
| 798 | Singleton<RuntimeObjectTable>::getInstance()->addInstance(test);
|
---|
| 799 |
|
---|
| 800 | BEGIN_CASE("1","getInstance(typeid)") {
|
---|
| 801 | if(RuntimeObjectTable::getInstance(typeid(TestCollectable)) != &test)
|
---|
| 802 | TEST_FAIL;
|
---|
| 803 | } END_CASE;
|
---|
| 804 |
|
---|
| 805 | BEGIN_CASE("2","getInstance<T>()") {
|
---|
| 806 | if(RuntimeObjectTable::getInstance<TestCollectable>() != &test)
|
---|
| 807 | TEST_FAIL;
|
---|
| 808 | } END_CASE;
|
---|
| 809 | } END_CASE;
|
---|
| 810 | } END_CASE;
|
---|
| 811 |
|
---|
| 812 | BEGIN_CASE("RuntimeObject","RuntimeObject") {
|
---|
| 813 | BEGIN_CASE("1","çæããã¨ç»é²ãããç ´æ£ã§æ¶æ»
|
---|
| 814 | ãã") {
|
---|
| 815 | TestRuntimeObject * ro;
|
---|
| 816 |
|
---|
| 817 | TestSuite::clearCheckpoints();
|
---|
| 818 |
|
---|
| 819 | TEST_CASE("0","[åæ] ç»é²ããã¦ããªã", RuntimeObjectTable::getInstance<TestRuntimeObject>() == 0);
|
---|
| 820 |
|
---|
| 821 | ro = new TestRuntimeObject;
|
---|
| 822 |
|
---|
| 823 | TEST_CASE("1","ã³ã³ã¹ãã©ã¯ã¿ãå®è¡ããã¦ãã", TestSuite::isReached("TestRuntimeObject::TestRuntimeObject"));
|
---|
| 824 | TEST_CASE("2","ç»é²ããã¦ãã", RuntimeObjectTable::getInstance<TestRuntimeObject>() == ro);
|
---|
| 825 |
|
---|
| 826 | delete ro;
|
---|
| 827 |
|
---|
| 828 | TEST_CASE("3","ãã¹ãã©ã¯ã¿ãå®è¡ããã¦ãã", TestSuite::isReached("TestRuntimeObject::~TestRuntimeObject"));
|
---|
| 829 | TEST_CASE("4","ç»é²ã解é¤ããã¦ãã", RuntimeObjectTable::getInstance<TestRuntimeObject>() == 0);
|
---|
| 830 |
|
---|
| 831 | } END_CASE;
|
---|
| 832 |
|
---|
| 833 | BEGIN_CASE("2","èªåç ´æ£ã®ãã§ãã¯") {
|
---|
| 834 | TestRuntimeObject * ro;
|
---|
| 835 | TestRuntimeObject2 * ro2;
|
---|
| 836 |
|
---|
| 837 | TestSuite::clearCheckpoints();
|
---|
| 838 |
|
---|
| 839 | TEST_CASE("0","[åæ] ç»é²ããã¦ããªã", RuntimeObjectTable::getInstance<TestRuntimeObject>() == 0);
|
---|
| 840 | TEST_CASE("0","[åæ] ç»é²ããã¦ããªã", RuntimeObjectTable::getInstance<TestRuntimeObject2>() == 0);
|
---|
| 841 |
|
---|
| 842 | ro = new TestRuntimeObject;
|
---|
| 843 | ro2 = new TestRuntimeObject2;
|
---|
| 844 |
|
---|
| 845 | TEST_CASE("1","ã³ã³ã¹ãã©ã¯ã¿ãå®è¡ããã¦ãã(ro)", TestSuite::isReached("TestRuntimeObject::TestRuntimeObject"));
|
---|
| 846 | TEST_CASE("2","ã³ã³ã¹ãã©ã¯ã¿ãå®è¡ããã¦ãã(ro2)", TestSuite::isReached("TestRuntimeObject2::TestRuntimeObject2"));
|
---|
| 847 | TEST_CASE("3","ç»é²ããã¦ãã(ro)", RuntimeObjectTable::getInstance<TestRuntimeObject>() == ro);
|
---|
| 848 | TEST_CASE("4","ç»é²ããã¦ãã(ro2)", RuntimeObjectTable::getInstance<TestRuntimeObject2>() == ro2);
|
---|
| 849 |
|
---|
| 850 | Singleton<RuntimeObjectTable>::getInstance()->clear();
|
---|
| 851 |
|
---|
| 852 | TEST_CASE("5","ãã¹ãã©ã¯ã¿ã¯å®è¡ããã¦ããªã (ro)", !TestSuite::isReached("TestRuntimeObject::~TestRuntimeObject"));
|
---|
| 853 | TEST_CASE("6","ãã¹ãã©ã¯ã¿ã¯å®è¡ããã¦ãã (ro2)", TestSuite::isReached("TestRuntimeObject2::~TestRuntimeObject2"));
|
---|
| 854 | TEST_CASE("7","ç»é²ã解é¤ããã¦ãã", RuntimeObjectTable::getInstance<TestRuntimeObject>() == 0);
|
---|
| 855 | TEST_CASE("8","ç»é²ã解é¤ããã¦ãã", RuntimeObjectTable::getInstance<TestRuntimeObject2>() == 0);
|
---|
| 856 |
|
---|
| 857 | delete ro;
|
---|
| 858 | } END_CASE;
|
---|
| 859 |
|
---|
| 860 | } END_CASE;
|
---|
| 861 |
|
---|
| 862 | Singleton<RuntimeObjectTable>::restoreContext(context);
|
---|
| 863 | }
|
---|
| 864 |
|
---|
| 865 | #endif
|
---|
| 866 |
|
---|