Witam
Mamy taki kod źródłowy:
class PC
{
public:
PC(u32 i){}
virtual ~PC(){}
};
class PCMock : public PC //it is mock for unit test needs
{
public:
PCMock() :PC(0){}
~PCMock(){}
//MOCK_METHOD1(....
};
class HC
{
public:
HC(){}
virtual ~HC(){}
virtual void execute(std::list<PC*>& configuration)
{
std::list<PC*>::iterator configurationIterator;
for (configurationIterator = configuration.begin();
configurationIterator != configuration.end();
++configurationIterator)
{
}
}
};
class HCUnderTest: public HC //for unit tests needs
{
public:
HCUnderTest(): HC(){}
~HCUnderTest(){}
//execute is not mocked
//using HC::something... which is protected in HC class
};
//...
//in some unit tests()
PCMock mock;
std::list<PC*> config;
config.push_back(&mock);
config.push_back(&mock);
config.push_back(&mock);
config.push_back(&mock);
HCUnderTest hw; //for "HC hw" it works
hw.execute(config);
Problem polega na tym, że, wywala mi błąd jak mam hw.execute(config) i obiekt "hw" jest typu HCUnderTest. Ale test przechodzi jak obiekt "hw" jest typu HC. Poniżej błąd.
Ktoś coś wie o co chodzi? Ja tu błędu oczywiście nie widzę. Dodam tylko tyle, że jak mamy definicję metody:
virtual void execute(std::list<PC*>* configuration)
zamiast
virtual void execute(std::list<PC*>& configuration)
i odpowiednio
hw.execute(&config);
to też to samo.
[ EXECUTE_TEST ] HCTest.someTest
Executing: gdb --quiet --batch --command=gdb-respfile-uMpVzm
[Thread debugging using libthread_db enabled]
0x55555430 in __kernel_vsyscall ()
* Loaded Libraries
From To Syms Read Shared Object Library
0x44cac670 0x44cb86e8 Yes (*) /lib/libpthread.so.0
0x555bb490 0x5562b818 Yes /opt/gcc/x86_64/4.7.3a-1/lib/libstdc++.so.6
0x44b1a470 0x44b34968 Yes (*) /lib/libm.so.6
0x5565ef70 0x55673a68 Yes /opt/gcc/x86_64/4.7.3a-1/lib/libgcc_s.so.1
0x4498db10 0x44ab7994 Yes (*) /lib/libc.so.6
0x44955830 0x4496d4bf Yes (*) /lib/ld-linux.so.2
(*): Shared library is missing debugging information.
* Threads
* 1 Thread 0x556795a0 (LWP 15927) 0x55555430 in __kernel_vsyscall ()
* FPU Status
R7: Empty 0x00000000000000000000
R6: Empty 0x00000000000000000000
R5: Empty 0x00000000000000000000
R4: Empty 0x00000000000000000000
R3: Empty 0x00000000000000000000
R2: Empty 0x00000000000000000000
R1: Empty 0x00000000000000000000
=>R0: Empty 0x00000000000000000000
Status Word: 0x0020 PE
TOP: 0
Control Word: 0x037f IM DM ZM OM UM PM
PC: Extended Precision (64-bits)
RC: Round to nearest
Tag Word: 0xffff
Instruction Pointer: 0x00:0x080da750
Operand Pointer: 0x00:0x0a306f80
Opcode: 0x0000
* Registers
eax 0xfffffe00 -512
ecx 0x85790d0 139956432
edx 0x0 0
ebx 0x3e3d 15933
esp 0x8579098 0x8579098
ebp 0x85790f8 0x85790f8
esi 0x857918c 139956620
edi 0x857968c 139957900
eip 0x55555430 0x55555430 <__kernel_vsyscall+16>
eflags 0x296 [ PF AF SF IF ]
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x63 99
* Backtrace
Thread 1 (Thread 0x556795a0 (LWP 15927)):
#0 0x55555430 in __kernel_vsyscall ()
No symbol table info available.
#1 0x44cb6483 in __waitpid_nocancel () from /lib/libpthread.so.0
No symbol table info available.
#2 0x0827dd53 in crash_catcher (signum=11, siginfo=0x857910c) at ../UnitTests/framework/gmock/crashhandler.cpp:271
status = -1
fd = {3, 4}
dbg_pid = 15933
#3 <signal handler called>
No symbol table info available.
#4 0x08205873 in HC::execute (this=0xa306810, configuration=Traceback (most recent call last):
File "/opt/gcc/x86_64/4.7.3a-1/lib/../share/gcc-4.7.3/python/libstdcxx/v6/printers.py", line 103, in children
nodetype = find_type(self.val.type, '_Node')
File "/opt/gcc/x86_64/4.7.3a-1/lib/../share/gcc-4.7.3/python/libstdcxx/v6/printers.py", line 43, in find_type
field = typ.fields()[0]
IndexError: list index out of range
std::list) at ../sourceFiles/HC.cpp:36
configurationIterator = Traceback (most recent call last):
File "/opt/gcc/x86_64/4.7.3a-1/lib/../share/gcc-4.7.3/python/libstdcxx/v6/printers.py", line 120, in to_string
nodetype = find_type(self.val.type, '_Node')
File "/opt/gcc/x86_64/4.7.3a-1/lib/../share/gcc-4.7.3/python/libstdcxx/v6/printers.py", line 45, in find_type
raise ValueError, "Cannot find type %s::%s" % (str(orig), name)
ValueError: Cannot find type std::list<PC*, std::allocator<PC*> >::iterator::_Node