source: anotherchoice/tags/jsp-1.4.4-full-UTF8/cfg/base/filecontainer.cpp@ 26

Last change on this file since 26 was 26, checked in by ykominami, 10 years ago

initial

File size: 27.8 KB
Line 
1/*
2 * TOPPERS/JSP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
5 *
6 * Copyright (C) 2000-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: filecontainer.cpp,v 1.11 2003/12/20 06:51:58 takayuki Exp $
51 */
52
53#ifdef _MSC_VER
54#pragma warning(disable:4786) //デバッグ文字列を255文字に切り詰めた
55#endif
56
57#include "base/filecontainer.h"
58#include <memory.h>
59#include <fstream>
60
61using namespace std;
62
63namespace {
64 /* 符号なし10進文字列のパース */
65 char * parse_uint(char * src, unsigned int * dest, unsigned int default_value = 0)
66 {
67 int result = 0;
68
69 if(*src < '0' || *src > '9') {
70 *dest = default_value;
71 return src;
72 }
73
74 do {
75 result = result * 10 + *(src++) - '0';
76 } while(*src >= '0' && *src <='9');
77
78 *dest = result;
79 return src;
80 }
81}
82
83 /* 変数情
84報の読み込み */
85void FileContainer::attachInfo(const string & filename) throw(Exception)
86{
87 char buffer[256];
88 fstream file;
89
90 char * work;
91 struct tagVariableInfo info;
92
93 memset(&info, 0, sizeof(info));
94
95 file.open(filename.c_str(), ios::in);
96 if(!file.is_open()) {
97 ExceptionMessage("Structure information file(%) was not found. ","構造体情
98報ファイル(%)が見つかりません ") << filename << throwException;
99 return;
100 }
101
102 while(!file.eof())
103 {
104 file.get(buffer, 256);
105
106 if(!file.fail()) {
107 switch(buffer[0])
108 {
109 case 's':
110 {
111 unsigned int address = 0;
112 unsigned int size = 0;
113
114 work = buffer+1;
115 while(*work != ',' && *work != '\x0')
116 work++;
117 if(*work != '\x0') {
118 *work = '\x0';
119 work = parse_uint(work+1,&size);
120 work = parse_uint(work+1,&address);
121 }
122
123 info.address = static_cast<address_t>(address);
124 info.size = static_cast<size_t>(size);
125 variableinfo[string(buffer+1)] = info;
126 break;
127 }
128
129 case 'd': //識別子名は無視
130 break;
131
132 default:
133 ExceptionMessage("Unknown information type identifier found - [%]","未知の型識別子 - [%]") << buffer[0] << throwException;
134 }
135 }
136 else
137 file.clear();
138
139 file.get();
140 }
141
142 file.close();
143}
144
145 /* 変数情
146報の取得 */
147struct FileContainer::tagVariableInfo FileContainer::getVariableInfo(const string & name) throw(Exception)
148{
149 map<string, tagVariableInfo>::const_iterator scope;
150
151 scope = variableinfo.find(name);
152 if(scope == variableinfo.end()) {
153 ExceptionMessage("Operation against the unknwon symbol [%] was rejected.","不明なシンボル名 [%] の情
154報を取得しようとしています") << name << throwException;
155
156 struct tagVariableInfo dummy;
157 memset(&dummy, 0, sizeof(dummy));
158 return dummy;
159 }
160
161 return scope->second;
162}
163
164
165 /* コンストラクタ (シンボル名を指定して初期化) */
166TargetVariableBase::TargetVariableBase(const std::string & sym) throw()
167 : address(0), size(0), offset(0), structure_size(0), loaded(false)
168{
169 try{
170 FileContainer * fc = FileContainer::getInstance();
171 address = fc->getSymbolAddress(sym);
172 size = fc->getVariableInfo(sym).size;
173 structure_size = size;
174 }
175 catch(...) {
176 address = 0;
177 size = 0;
178 }
179}
180
181 /* コンストラクタ (シンボル名, データ長を指定して初期化) */
182TargetVariableBase::TargetVariableBase(const string & sym, size_t _size) throw()
183 : address(0), size(_size), offset(0), structure_size(_size), loaded(false)
184{
185 try{
186 FileContainer * fc = FileContainer::getInstance();
187 address = fc->getSymbolAddress(sym);
188 }
189 catch(...) {
190 address = 0;
191 size = 0;
192 }
193}
194
195 /* コンストラクタ (シンボル名、メンバ名を指定して初期化) */
196TargetVariableBase::TargetVariableBase(const string & sym, const string & sz) throw()
197 : address(0), size(0), offset(0), structure_size(0), loaded(false)
198{
199 try{
200 FileContainer * fc = FileContainer::getInstance();
201 address = fc->getSymbolAddress(sym); //構造体のå…
202ˆé ­ã‚¢ãƒ‰ãƒ¬ã‚¹
203 size = fc->getVariableInfo(sz).size; //メンバ変数の長さ
204 offset = static_cast<size_t>(fc->getVariableInfo(sz).address); //メンバ変数のオフセット
205 structure_size = fc->getVariableInfo(sym).size; //構造体の長さ
206 }
207 catch(...) {
208 address = 0;
209 size = 0;
210 }
211}
212
213 /* コピーコンストラクタ */
214TargetVariableBase::TargetVariableBase(const TargetVariableBase & src) throw()
215 : address(0), size(0), offset(0), structure_size(0), loaded(false)
216{
217 if(src.isValid()) {
218 address = src.address;
219 size = src.size;
220 offset = src.offset;
221 structure_size = src.structure_size;
222 loaded = false;
223 }
224}
225
226
227 /* オブジェクト内
228容の取得 */
229void TargetVariableBase::loadContent(void * dest, size_t dest_size) throw(Exception)
230{
231 char * buffer = 0;
232
233 try {
234 if(isValid()) {
235 buffer = new char[getSize()];
236 FileContainer * fc = FileContainer::getInstance();
237
238 fc->loadContents(buffer, getAddress() + getOffset(), getSize());
239 if(fc->getByteOrder() != FileContainer::HOSTORDER)
240 changeEndian(buffer, getSize());
241
242 if(size < dest_size)
243 memset(dest, 0, dest_size);
244 else if(size > dest_size)
245 ExceptionMessage("[TargetVariableBase::loadContent] Destination storage is too small to store the contents.","[TargetVariableBase::loadContent] 出力å…
246ˆãƒãƒƒãƒ•ã‚¡ã®ã‚µã‚¤ã‚ºãŒå°ã•ã™ãŽã¾ã™").throwException();
247 memcpy(dest, buffer, getSize());
248
249 delete [] buffer;
250 loaded = true;
251 }
252 else {
253 ExceptionMessage("loadContent was performed with an illegal target variable.","不正なターゲット変数情
254報でloadContentが呼ばれました").throwException();
255 }
256 }
257 catch(bad_alloc &) {
258 ExceptionMessage("No available memory [%B]","メモリ不足です [%B]") << (unsigned int)getSize() << throwException;
259 }
260 catch(Exception &) {
261 if(buffer)
262 delete [] buffer;
263 throw;
264 }
265}
266
267 /* バイトオーダの変更 */
268void TargetVariableBase::changeEndian(char * buffer, size_t size) throw()
269{
270 char * tail = buffer + size - 1;
271
272 while(buffer < tail) {
273 char temporary = *buffer;
274 *buffer = *tail;
275 *tail = temporary;
276
277 ++ buffer;
278 -- tail;
279 }
280}
281
282
283
284//---------------------------------------------
285
286#ifdef TESTSUITE
287#include "base/coverage_undefs.h"
288
289#include <cctype>
290#define _isprint(x) isprint(x)
291
292class TFileContainer : public FileContainer
293{
294public:
295 TFileContainer(void) throw() {}
296 virtual ~TFileContainer(void) throw() {}
297
298 string module;
299 void attachModule(const std::string & _module) throw(Exception)
300 {
301 CHECKPOINT("attachModule");
302 module = _module;
303 }
304
305 void * dest;
306 address_t addr;
307 size_t sz;
308 void loadContents(void * _dest, address_t _addr, size_t _sz) throw(Exception)
309 {
310 CHECKPOINT("loadContents");
311 dest = _dest;
312 addr = _addr;
313 sz = _sz;
314 memset(_dest, ~0, _sz);
315 }
316
317 string symbol;
318 address_t getSymbolAddress(const std::string & _symbol) throw(Exception)
319 {
320 CHECKPOINT("getSymbolAddress");
321 symbol = _symbol;
322 return 1;
323 }
324
325 std::string getArchitecture(void) throw(Exception)
326 { return "TFileContainer"; }
327
328 TESTSUITE_PROTOTYPE(main)
329};
330
331TESTSUITE(main, TFileContainer)
332{
333 PREDECESSOR("SingletonBase");
334 PREDECESSOR("RuntimeObjectTable");
335
336 SingletonBase::ContextChain chain;
337 chain.saveContext<RuntimeObjectTable>();
338 chain.renewInstance();
339
340 BEGIN_CASE("getInstance","getInstance") {
341 BEGIN_CASE("1","何も登録されていないときのgetInstanceで例外") {
342 bool result = false;
343 try { FileContainer::getInstance(); } catch(Exception &) { result = true; }
344 if(!result)
345 TEST_FAIL;
346 } END_CASE;
347
348 BEGIN_CASE("2","getInstanceでインスタンスが返る") {
349 TFileContainer fc;
350 FileContainer * instance;
351 bool result = true;
352 try { instance = FileContainer::getInstance(); } catch(...) { result = false; }
353 TEST_CASE("1","例外はおきない", result);
354 TEST_CASE("2","取得できるインスタンスが正しい", instance == &fc);
355 } END_CASE;
356 } END_CASE;
357
358 BEGIN_CASE("parse_uint","parse_uint") {
359 BEGIN_CASE("1","数字を切り出せる") {
360 unsigned int dest;
361 char * src = "123";
362 char * result = parse_uint(src, &dest);
363
364 TEST_CASE("1","resultが最後に来ている", result == src + 3);
365 TEST_CASE("2","値は正しい", dest == 123);
366 } END_CASE;
367
368 BEGIN_CASE("2","数字で無い文字を与えるとデフォルト値が返る") {
369 unsigned int dest;
370 char * src = "abc";
371 char * result = parse_uint(src, &dest, 1234567);
372
373 TEST_CASE("1","resultは進んでいない", result == src);
374 TEST_CASE("2","デフォルト値が返る", dest == 1234567);
375 } END_CASE;
376
377 BEGIN_CASE("3","デリミタでとまる") {
378 unsigned int dest;
379 char * src = "321,123";
380 char * result = parse_uint(src, &dest);
381
382 TEST_CASE("1","resultは進んでいない", result == src + 3);
383 TEST_CASE("2","デフォルト値が返る", dest == 321);
384 } END_CASE;
385 } END_CASE;
386
387 BEGIN_CASE("attachInfo","attachInfo") {
388 BEGIN_CASE("1","普通に処理をさせる") {
389 fstream file("dummy",ios::out);
390 file << "s_kernel_tinib_table,32,0\nstask_initialization_block::texrtn,4,28\n";
391 file.close();
392
393 TFileContainer fc;
394
395 bool result = true;
396 try { fc.attachInfo("dummy"); } catch(...) { result = false; }
397
398 TEST_CASE("1","例外はおきない", result);
399
400 map<string, struct tagVariableInfo>::iterator scope = fc.variableinfo.find("_kernel_tinib_table");
401 TEST_CASE("2","要素が追加されている (tinib)", scope != fc.variableinfo.end());
402 TEST_CASE("3","値が正しい (tinib)", scope->second.size == 32);
403
404 scope = fc.variableinfo.find("task_initialization_block::texrtn");
405 TEST_CASE("4","要素が追加されている (texrtn)", scope != fc.variableinfo.end());
406 TEST_CASE("5","値が正しい (texrtn.size)", scope->second.size == 4);
407 TEST_CASE("6","値が正しい (texrtn.address)", scope->second.address == 28);
408 } END_CASE;
409 remove("dummy");
410
411 BEGIN_CASE("2","識別文字 'd' を無視する") {
412 fstream file("dummy",ios::out);
413 file << "ddummy,0\ndtask_initialization_block::texrtn,4,28\n";
414 file.close();
415
416 TFileContainer fc;
417
418 bool result = true;
419 try { fc.attachInfo("dummy"); } catch(...) { result = false; }
420
421 TEST_CASE("1","例外はおきない", result);
422 TEST_CASE("2","要素は追加されていない", fc.variableinfo.size() == 0);
423 } END_CASE;
424 remove("dummy");
425
426 BEGIN_CASE("3","空行を無視できる") {
427 fstream file("dummy",ios::out);
428 file << "s_kernel_tinib_table,32,0\n\nstask_initialization_block::texrtn,4,28\n";
429 file.close();
430
431 TFileContainer fc;
432
433 bool result = true;
434 try { fc.attachInfo("dummy"); } catch(...) { result = false; }
435
436 TEST_CASE("1","例外はおきない", result);
437
438 map<string, struct tagVariableInfo>::iterator scope = fc.variableinfo.find("_kernel_tinib_table");
439 TEST_CASE("2","要素が追加されている (tinib)", scope != fc.variableinfo.end());
440 TEST_CASE("3","値が正しい (tinib)", scope->second.size == 32);
441
442 scope = fc.variableinfo.find("task_initialization_block::texrtn");
443 TEST_CASE("4","要素が追加されている (texrtn)", scope != fc.variableinfo.end());
444 TEST_CASE("5","値が正しい (texrtn.size)", scope->second.size == 4);
445 TEST_CASE("6","値が正しい (texrtn.address)", scope->second.address == 28);
446 } END_CASE;
447 remove("dummy");
448
449 BEGIN_CASE("4","'s'と'd'以外をはじく") {
450 char c;
451 char msg[2] = {0, 0};
452
453 for(c=0;c<128;++c) {
454 if(isprint(c) && (c != 's' && c != 'd')) {
455 fstream file("dummy",ios::out);
456 file << c;
457 file << "dummy,0\n";
458 file.close();
459
460 TFileContainer fc;
461
462 bool result = false;
463 try { fc.attachInfo("dummy"); } catch(...) { result = true; }
464
465 msg[0] = c;
466 TEST_CASE_("1","例外がおきる", result, string(msg));
467 TEST_CASE_("2","要素は追加されていない", fc.variableinfo.size() == 0, string(msg));
468 }
469 }
470 } END_CASE;
471 remove("dummy");
472 } END_CASE;
473
474 chain.restoreContext();
475}
476
477class TTargetVariable : public TargetVariable<int>
478{
479 TESTSUITE_PROTOTYPE(main)
480
481 /*
482 * コンストラクタ (TargetVariable<int>に回送)
483 */
484 inline TTargetVariable(FileContainer::address_t addr) throw()
485 : TargetVariable<int>(addr)
486 {}
487
488 inline TTargetVariable(FileContainer::address_t addr, size_t sz) throw()
489 : TargetVariable<int>(addr, sz)
490 {}
491
492 inline TTargetVariable(FileContainer::address_t addr, size_t sz, size_t ofs, size_t ssz) throw()
493 : TargetVariable<int>(addr, sz, ofs, ssz)
494 {}
495
496 inline TTargetVariable(const std::string & sym) throw()
497 : TargetVariable<int>(sym)
498 {}
499
500 inline TTargetVariable(const std::string & sym, const std::string & sz) throw()
501 : TargetVariable<int>(sym, sz)
502 {}
503
504 /* デストラクタ (特に何もしない) */
505 virtual ~TTargetVariable(void) throw()
506 {}
507};
508
509TESTSUITE(main, TTargetVariable)
510{
511 PREDECESSOR("SingletonBase");
512 PREDECESSOR("TFileContainer");
513 PREDECESSOR("RuntimeObjectTable");
514
515 SingletonBase::ContextChain chain;
516 chain.saveContext<RuntimeObjectTable>();
517 chain.renewInstance();
518
519 TFileContainer fc;
520 fstream file("dummy",ios::out);
521 file << "s_test,4,0\ns_kernel_tinib_table,32,0\nstask_initialization_block::texrtn,4,28\n";
522 file.close();
523
524 fc.attachInfo("dummy");
525
526 BEGIN_CASE("constructor","コンストラクタ") {
527 BEGIN_CASE("1", "(address_t, size_t)") {
528 TTargetVariable tv(1, 2);
529
530 TEST_CASE("1","変数は有効", tv.isValid());
531 TEST_CASE("2","アドレスは正しい", tv.getAddress() == 1);
532 TEST_CASE("3","サイズは正しい", tv.getSize() == 2);
533 TEST_CASE("4","オフセットは0", tv.getOffset() == 0);
534 TEST_CASE("5","構造体サイズは変数サイズと一緒", tv.getStructureSize() == tv.getSize());
535 } END_CASE;
536
537 BEGIN_CASE("2","(address_t, size_t, size_t, size_t)") {
538 TTargetVariable tv(1,2,3,4);
539
540 TEST_CASE("1","変数は有効", tv.isValid());
541 TEST_CASE("2","アドレスは正しい", tv.getAddress() == 1);
542 TEST_CASE("3","サイズは正しい", tv.getSize() == 2);
543 TEST_CASE("4","オフセットは正しい", tv.getOffset() == 3);
544 TEST_CASE("5","構造体サイズは正しい", tv.getStructureSize() == 4);
545 } END_CASE;
546
547 BEGIN_CASE("3","(string)") {
548 TestSuite::clearCheckpoints();
549
550 TTargetVariable tv("_test");
551
552 TEST_CASE("1","変数は有効", tv.isValid());
553 TEST_CASE("2","getSymbolAddressがコールされている", TestSuite::isReached("getSymbolAddress"));
554 TEST_CASE("3","getSymbolAddressの引数が正しい", fc.symbol.compare("_test") == 0);
555 TEST_CASE("3","アドレスは正しい", tv.getAddress() == 1);
556 TEST_CASE("4","サイズは正しい", tv.getSize() == 4);
557 TEST_CASE("5","オフセットは正しい", tv.getOffset() == 0);
558 TEST_CASE("6","構造体サイズは正しい", tv.getStructureSize() == 4);
559 } END_CASE;
560
561 BEGIN_CASE("4","(string,string)") {
562 TestSuite::clearCheckpoints();
563
564 TTargetVariable tv("_kernel_tinib_table", "task_initialization_block::texrtn");
565
566 TEST_CASE("1","変数は有効", tv.isValid());
567 TEST_CASE("2","getSymbolAddressがコールされている", TestSuite::isReached("getSymbolAddress"));
568 TEST_CASE("3","getSymbolAddressの引数が正しい", fc.symbol.compare("_kernel_tinib_table") == 0);
569 TEST_CASE("3","アドレスは正しい", tv.getAddress() == 1);
570 TEST_CASE("4","サイズは正しい", tv.getSize() == 4);
571 TEST_CASE("5","オフセットは正しい", tv.getOffset() == 28);
572 TEST_CASE("6","構造体サイズは正しい", tv.getStructureSize() == 32);
573 } END_CASE;
574
575 BEGIN_CASE("5","無効なケース") {
576 TEST_CASE("1","アドレス0の変数は無効 (1)", !TTargetVariable(0,4).isValid());
577 TEST_CASE("2","アドレス0の変数は無効 (2)", !TTargetVariable(0,4,4,4).isValid());
578 TEST_CASE("3","サイズ0の変数は無効 (1)", !TTargetVariable(4,0).isValid());
579 TEST_CASE("4","サイズ0の変数は無効 (2)", !TTargetVariable(4,0,4,4).isValid());
580 TEST_CASE("5","構造体サイズ0の変数は無効", !TTargetVariable(4,4,4,0).isValid());
581
582 TEST_CASE("6","存在しないシンボル名の変数も無効(1)", !TTargetVariable("unknown").isValid());
583 TEST_CASE("7","存在しないシンボル名の変数も無効(2)", !TTargetVariable("unknown","task_initialization_block::texrtn").isValid());
584 TEST_CASE("8","存在しないメンバ名の変数も無効", !TTargetVariable("_kernel_tinib_table","unknown").isValid());
585
586 TEST_CASE("10","格納領域が不足している変数", !TTargetVariable("_kernel_tinib_table").isValid());
587 TEST_CASE("11","無効な引数をもらった場合", !TTargetVariable(*((TTargetVariable *)0)).isValid());
588 } END_CASE;
589 } END_CASE;
590
591 BEGIN_CASE("loadContents", "loadContents") {
592 BEGIN_CASE("1","通常起動") {
593 int i;
594 TTargetVariable tv(0x100);
595
596 bool result = true;
597 try { tv.loadContent(&i, sizeof(int)); } catch(...) { result = false; }
598
599 TEST_CASE("1","例外は起こらない", result);
600 TEST_CASE("2","中身は~0でフィルされている", i == ~0);
601 } END_CASE;
602
603 BEGIN_CASE("2","å…
604ƒã‚ˆã‚Šã‚‚大きな型で受ける") {
605 struct { int first; int second; } i;
606 TTargetVariable tv(0x100);
607
608 bool result = true;
609 try { tv.loadContent(&i, sizeof(i)); } catch(...) { result = false; }
610
611 TEST_CASE("1","例外は起こらない", result);
612 TEST_CASE("2","中身は~0でフィルされている", i.first == ~0);
613 TEST_CASE("3","残りは0でフィルされている", i.second == 0);
614 } END_CASE;
615
616 BEGIN_CASE("3","無効な要素に対して実行する") {
617 TTargetVariable tv(0, 0, 0, 0);
618 int i;
619
620 bool result = false;
621 try{ tv.loadContent(&i, sizeof(i)); } catch(...) { result = true; }
622 TEST_CASE("1","例外が起きる", result);
623 } END_CASE;
624
625 BEGIN_CASE("4","å…
626ƒã‚ˆã‚Šã‚‚小さな型で受ける") {
627 char i;
628 TTargetVariable tv(0x100);
629
630 bool result = false;
631 try { tv.loadContent(&i, sizeof(i)); } catch(...) { result = true; }
632
633 TEST_CASE("1","例外が起こる", result);
634 } END_CASE;
635
636 } END_CASE;
637
638 BEGIN_CASE("pointer_operators","ポインタ風の演算") {
639 TargetVariable<int> tv(0x100);
640 TargetVariable<int> tvl(0x100);
641
642 *tvl;
643
644 TEST_CASE("0","[前提] tv:アドレスは0x100", tv.getAddress() == 0x100);
645 TEST_CASE("0","[前提] tv:サイズは4", tv.getSize() == 4);
646 TEST_CASE("0","[前提] tv:構造体サイズも4", tv.getStructureSize() == 4);
647 TEST_CASE("0","[前提] tv:読出し未了", !tv.isLoaded());
648 TEST_CASE("0","[前提] tvl:アドレスは0x100", tvl.getAddress() == 0x100);
649 TEST_CASE("0","[前提] tvl:サイズは4", tvl.getSize() == 4);
650 TEST_CASE("0","[前提] tvl:構造体サイズも4", tvl.getStructureSize() == 4);
651 TEST_CASE("0","[前提] tvl:読出し完了", tvl.isLoaded());
652
653 BEGIN_CASE("1","operator +") {
654 TestSuite::clearCheckpoints();
655
656 TargetVariable<int> work = tv + 0x10;
657 TEST_CASE("1","workのアドレスは0x140", work.getAddress() == 0x100 + sizeof(int) * 0x10);
658 TEST_CASE("2","workは読み込まれていない", !work.isLoaded());
659 } END_CASE;
660
661 BEGIN_CASE("2","operator -") {
662 TestSuite::clearCheckpoints();
663
664 TargetVariable<int> work = tv - 0x10;
665 TEST_CASE("1","workのアドレスは0xc0", work.getAddress() == 0x100 - sizeof(int) * 0x10);
666 TEST_CASE("2","workは読み込まれていない", !work.isLoaded());
667 } END_CASE;
668
669 BEGIN_CASE("3","operator ++") {
670 TestSuite::clearCheckpoints();
671
672 TargetVariable<int> work(tvl);
673
674 TargetVariable<int> result = (++ work);
675
676 TEST_CASE("1","workのアドレスは0x104", work.getAddress() == 0x100 + sizeof(int));
677 TEST_CASE("2","work == result", work == result);
678 TEST_CASE("3","読み込み未了状æ…
679‹", !result.isLoaded());
680 } END_CASE;
681
682 BEGIN_CASE("4","operator ++(int)") {
683 TestSuite::clearCheckpoints();
684
685 TargetVariable<int> work(tvl);
686
687 TargetVariable<int> result = (work++);
688
689 TEST_CASE("1","workのアドレスは0x104", work.getAddress() == 0x100 + sizeof(int));
690 TEST_CASE("2","resultのアドレスは0x100", result.getAddress() == 0x100);
691 TEST_CASE("3","読み込み完了状æ…
692‹", result.isLoaded());
693 } END_CASE;
694
695 BEGIN_CASE("5","operator --") {
696 TestSuite::clearCheckpoints();
697
698 TargetVariable<int> work(tvl);
699
700 TargetVariable<int> result = (-- work);
701
702 TEST_CASE("1","workのアドレスは0x9c", work.getAddress() == 0x100 - sizeof(int));
703 TEST_CASE("2","work == result", work == result);
704 TEST_CASE("3","読み込み未了状æ…
705‹", !result.isLoaded());
706 } END_CASE;
707
708 BEGIN_CASE("6","operator --(int)") {
709 TestSuite::clearCheckpoints();
710
711 TargetVariable<int> work(tvl);
712
713 TargetVariable<int> result = (work--);
714
715 TEST_CASE("1","workのアドレスは0x9c", work.getAddress() == 0x100 - sizeof(int));
716 TEST_CASE("2","resultのアドレスは0x100", result.getAddress() == 0x100);
717 TEST_CASE("3","読み込み完了状æ…
718‹", result.isLoaded());
719 } END_CASE;
720
721 BEGIN_CASE("7","operator +=") {
722 TestSuite::clearCheckpoints();
723
724 TargetVariable<int> work(tvl);
725
726 work += 0x10;
727
728 TEST_CASE("1","workのアドレスは0x140", work.getAddress() == 0x100 + sizeof(int) * 0x10);
729 TEST_CASE("2","読み込み未了状æ…
730‹", !work.isLoaded());
731 } END_CASE;
732
733 BEGIN_CASE("8","operator -=") {
734 TestSuite::clearCheckpoints();
735
736 TargetVariable<int> work(tvl);
737
738 work -= 0x10;
739
740 TEST_CASE("1","workのアドレスは0xc0", work.getAddress() == 0x100 - sizeof(int) * 0x10);
741 TEST_CASE("2","読み込み未了状æ…
742‹", !work.isLoaded());
743 } END_CASE;
744
745 BEGIN_CASE("9", "operator &") {
746 TEST_CASE("1","アドレスが抜ける", &tv == 0x100);
747 TEST_CASE("2","NULLインスタンスには0が返る", &(*((TargetVariable<int> *)0)) == 0);
748 } END_CASE;
749
750 BEGIN_CASE("10", "operator *") {
751 TestSuite::clearCheckpoints();
752 TargetVariable<int> work(0x100);
753
754 const void * result = &(*work);
755
756 TEST_CASE("1","loadContentsが実行されている", TestSuite::isReached("loadContents"));
757 TEST_CASE("2","引数が正しい", fc.addr == 0x100);
758 TEST_CASE("3","引数が正しい", fc.sz == sizeof(int));
759
760 TestSuite::clearCheckpoints();
761 *work;
762
763 TEST_CASE("4","loadContentsは実行されない", !TestSuite::isReached("loadContents"));
764 } END_CASE;
765
766 BEGIN_CASE("11","operator ==/!=") {
767 TEST_CASE("1","アドレスが一致すればOK", tv == TTargetVariable(tv.getAddress()));
768 TEST_CASE("2","NULLインスタンスとの比較もできる", tv != *((TTargetVariable *)0));
769 } END_CASE;
770
771 BEGIN_CASE("cvr","カバレッジ対策") {
772
773 (*((TTargetVariable *)0)) ++;
774
775 } END_CASE;
776
777 } END_CASE;
778
779 chain.restoreContext();
780}
781
782
783#endif
784
Note: See TracBrowser for help on using the repository browser.