[0.1.x] updated : intBase tests passed

git-svn-id: https://pykd.svn.codeplex.com/svn@71744 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-11-25 07:18:38 +00:00 committed by Mikhail I. Izmestev
parent 664f6e4c69
commit 816827ec9f
8 changed files with 410 additions and 172 deletions

View File

@ -96,84 +96,37 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_compareMemory, DebugClient::
BOOST_PYTHON_MODULE( pykd ) BOOST_PYTHON_MODULE( pykd )
{ {
python::class_<intBase>( "intBase", "intBase", python::no_init ) python::class_<intBase>( "intBase", "intBase", python::no_init )
.def( int_( python::self ) ) .def( python::init<python::object&>() )
.def( "__long__", &intBase::convertLong ) .def( "__eq__", &intBase::eq )
.def( "__ne__", &intBase::ne)
.def( python::self + ULONG64() ) .def( "__lt__", &intBase::lt)
.def( ULONG64() + python::self ) .def( "__gt__", &intBase::gt )
.def( python::self += ULONG64() ) .def( "__le__", &intBase::le )
.def( python::self + python::self ) .def( "__ge__", &intBase::ge )
.def( python::self += python::self ) .def( "__add__", &intBase::add )
.def( "__radd__", &intBase::add )
.def( python::self - ULONG64() ) .def( "__sub__", &intBase::sub )
.def( ULONG64() - python::self ) .def( "__rsub__", &intBase::rsub )
.def( python::self -= ULONG64() ) .def( "__mul__", &intBase::mul )
.def( python::self - python::self ) .def( "__rmul__", &intBase::mul )
.def( python::self -= python::self ) .def( "__div__", &intBase::div )
.def( "__rdiv__", &intBase::rdiv )
.def( python::self * ULONG64() ) .def( "__mod__", &intBase::mod )
.def( ULONG64() * python::self ) .def( "__rmod__", &intBase::rmod )
.def( python::self *= ULONG64() ) .def( "__rshift__", &intBase::rshift )
.def( python::self * python::self ) .def( "__rrshift__", &intBase::rrshift )
.def( python::self *= python::self ) .def( "__lshift__", &intBase::lshift )
.def( "__rlshift__", &intBase::rlshift )
.def( python::self / ULONG64() ) .def( "__and__", &intBase::and )
.def( ULONG64() / python::self ) .def( "__rand__", &intBase::and )
.def( python::self /= ULONG64() ) .def( "__or__", &intBase::or )
.def( python::self / python::self ) .def( "__ror__", &intBase::or )
.def( python::self /= python::self ) .def( "__xor__", &intBase::xor )
.def( "__rxor__", &intBase::xor )
.def( python::self % ULONG64() ) .def( "__neg__", &intBase::neg )
.def( ULONG64() % python::self ) .def( "__pos__", &intBase::pos )
.def( python::self %= ULONG64() ) .def( "__invert__", &intBase::invert )
.def( python::self % python::self ) .def( "__nonzero__", &intBase::nonzero )
.def( python::self %= python::self )
.def( python::self & ULONG64() )
.def( ULONG64() & python::self )
.def( python::self &= ULONG64() )
.def( python::self & python::self )
.def( python::self &= python::self )
.def( python::self | ULONG64() )
.def( ULONG64() | python::self )
.def( python::self |= ULONG64() )
.def( python::self | python::self )
.def( python::self |= python::self )
.def( python::self ^ ULONG64() )
.def( ULONG64() ^ python::self )
.def( python::self ^= ULONG64() )
.def( python::self ^ python::self )
.def( python::self ^= python::self )
.def( python::self << ULONG64() )
.def( python::self <<= ULONG64() )
.def( python::self >> ULONG64() )
.def( python::self >>= ULONG64() )
.def( python::self < ULONG64() )
.def( python::self < python::self )
.def( python::self <= ULONG64() )
.def( python::self <= python::self )
.def( python::self == ULONG64() )
.def( python::self == boost::python::self )
.def( python::self >= ULONG64() )
.def( python::self >= boost::python::self )
.def( python::self > ULONG64() )
.def( python::self > boost::python::self )
.def( python::self != ULONG64() )
.def( python::self != boost::python::self )
.def( ~boost::python::self )
.def( !boost::python::self )
.def( "__str__", &intBase::str ) .def( "__str__", &intBase::str )
.def( "__hex__", &intBase::hex ); .def( "__hex__", &intBase::hex );
@ -366,11 +319,11 @@ BOOST_PYTHON_MODULE( pykd )
"Wait for events that breaks into the debugger" ); "Wait for events that breaks into the debugger" );
python::class_<TypeInfo, TypeInfoPtr, boost::noncopyable >("typeInfo", "Class representing typeInfo", python::no_init ) python::class_<TypeInfo, TypeInfoPtr, boost::noncopyable >("typeInfo", "Class representing typeInfo", python::no_init )
.def( "name", &pykd::TypeInfo::getName ) .def( "name", &TypeInfo::getName )
.def( "size", &pykd::TypeInfo::getSize ) .def( "size", &TypeInfo::getSize )
.def( "offset", &pykd::TypeInfo::getOffset ) .def( "offset", &TypeInfo::getOffset )
.def( "field", &pykd::TypeInfo::getField ) .def( "field", &TypeInfo::getField )
.def( "__getattr__", &pykd::TypeInfo::getField ); .def( "__getattr__", &TypeInfo::getField );
python::class_<TypedVar, TypedVarPtr, python::bases<intBase>, boost::noncopyable >("typedVar", python::class_<TypedVar, TypedVarPtr, python::bases<intBase>, boost::noncopyable >("typedVar",
"Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance",

View File

@ -2,92 +2,201 @@
namespace pykd { namespace pykd {
class intBase : boost::integer_arithmetic<intBase> typedef boost::variant<LONG, ULONG, LONG64, ULONG64, bool> BaseTypeVariant;
class VariantToStr : public boost::static_visitor<std::string>
{ {
public:
template<typename T>
std::string operator()(T i ) const {
std::stringstream sstr;
sstr << i;
return sstr.str();
}
};
class VariantToHex : public boost::static_visitor<std::string>
{
public:
template<typename T>
std::string operator()(T i ) const {
std::stringstream sstr;
sstr << std::hex << i;
return sstr.str();
}
};
class VariantToPyobj : public boost::static_visitor<python::object>
{
public:
template<typename T>
python::object operator()(T i ) const {
return python::object( i );
}
};
class intBase {
public: public:
operator ULONG64() const { intBase(python::object &obj) {
return getValue(); m_variant = convertToVar(obj);
} }
intBase& operator= ( ULONG64 val ) { intBase() : m_variant(LONG(0))
setValue( val ); {}
return *this;
}
virtual ULONG64 getValue() const { std::string
return m_intValue; str() {
} return boost::apply_visitor( VariantToStr(), getValue() );
virtual void setValue( ULONG64 value ) {
m_intValue = value;
} }
std::string std::string
str() const { hex() {
std::stringstream ss; return boost::apply_visitor( VariantToHex(), getValue() );
ss << getValue();
return ss.str();
} }
std::string python::object eq( python::object& obj ) {
hex() const { return boost::apply_visitor( VariantToPyobj(), getValue() ) == obj;
std::stringstream ss;
ss << std::hex << getValue();
return ss.str();
} }
template <class T> python::object ne( python::object& obj ) {
bool operator!=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) != obj;
{ return getValue() == rhs; } }
template <class T> python::object lt( python::object& obj ) {
intBase& operator+=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) < obj;
{ setValue( getValue() + rhs ); return *this; } }
template <class T> python::object gt( python::object& obj ) {
intBase& operator-=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) > obj;
{ setValue( getValue() - rhs ); return *this; } }
template <class T> python::object le( python::object& obj ) {
intBase& operator*=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) <= obj;
{ setValue( getValue() * rhs ); return *this; } }
template <class T> python::object ge( python::object& obj ) {
intBase& operator/=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) >= obj;
{ setValue( getValue() / rhs ); return *this; } }
template <class T> python::object add( python::object& obj ) {
intBase& operator%=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) + obj;
{ setValue( getValue() % rhs ); return *this; } }
template <class T> python::object sub( python::object& obj ) {
intBase& operator&=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) - obj;
{ setValue( getValue() & rhs ); return *this; } }
template <class T> python::object rsub( python::object& obj ) {
intBase& operator|=(T const& rhs) return obj - boost::apply_visitor( VariantToPyobj(), getValue() );
{ setValue( getValue() | rhs ); return *this; } }
template <class T> python::object mul( python::object& obj ) {
intBase& operator^=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) * obj;
{ setValue( getValue() ^ rhs ); return *this; } }
template <class T> python::object div( python::object& obj ) {
intBase& operator<<=(T const& rhs) return boost::apply_visitor( VariantToPyobj(), getValue() ) / obj;
{ setValue( getValue() << rhs ); return *this; } }
template <class T> python::object rdiv( python::object& obj ) {
intBase& operator>>=(T const& rhs) return obj / boost::apply_visitor( VariantToPyobj(), getValue() );
{ setValue( getValue() >> rhs ); return *this; } }
PyObject* convertLong() { return PyLong_FromLongLong( getValue() ); } python::object mod( python::object& obj ) {
return boost::apply_visitor( VariantToPyobj(), getValue() ) % obj;
}
python::object rmod( python::object& obj ) {
return obj % boost::apply_visitor( VariantToPyobj(), getValue() );
}
python::object rshift( python::object& obj ) {
return boost::apply_visitor( VariantToPyobj(), getValue() ) >> obj;
}
python::object rrshift( python::object& obj ) {
return obj >> boost::apply_visitor( VariantToPyobj(), getValue() );
}
python::object lshift( python::object& obj ) {
return boost::apply_visitor( VariantToPyobj(), getValue() ) << obj;
}
python::object rlshift( python::object& obj ) {
return obj << boost::apply_visitor( VariantToPyobj(), getValue() );
}
python::object and( python::object& obj ) {
return boost::apply_visitor( VariantToPyobj(), getValue() ) & obj;
}
python::object or( python::object& obj ) {
return boost::apply_visitor( VariantToPyobj(), getValue() ) | obj;
}
python::object xor( python::object& obj ) {
return boost::apply_visitor( VariantToPyobj(), getValue() ) ^ obj;
}
python::object neg() {
return 0 - boost::apply_visitor( VariantToPyobj(), getValue() );
}
python::object pos() {
return 0 + boost::apply_visitor( VariantToPyobj(), getValue() );
}
python::object invert() {
return boost::apply_visitor( VariantToPyobj(), getValue() ) ^ boost::apply_visitor( VariantToPyobj(), getValue() );
}
python::object nonzero() {
return boost::apply_visitor( VariantToPyobj(), getValue() ) != 0;
}
private: private:
ULONG64 m_intValue; virtual BaseTypeVariant getValue() {
return m_variant;
}
BaseTypeVariant convertToVar( python::object &obj )
{
if ( PyBool_Check( obj.ptr() ) )
{
if ( obj.ptr() == Py_True )
return BaseTypeVariant(true);
return BaseTypeVariant(false);
}
else if ( _PyLong_Sign( obj.ptr() ) >= 0 )
{
if ( PyInt_CheckExact( obj.ptr() ) )
return BaseTypeVariant( ULONG( PyLong_AsUnsignedLong( obj.ptr() ) ) );
else
if( PyLong_CheckExact( obj.ptr() ) )
return BaseTypeVariant( ULONG64( PyLong_AsUnsignedLongLong( obj.ptr() ) ) );
}
else
{
if ( PyInt_CheckExact( obj.ptr() ) )
return BaseTypeVariant( LONG( PyLong_AsLong( obj.ptr() ) ) );
else
if( PyLong_CheckExact( obj.ptr() ) )
return BaseTypeVariant( LONG64( PyLong_AsLongLong( obj.ptr() ) ) );
}
return BaseTypeVariant( false );
}
BaseTypeVariant m_variant;
}; };
}; };

View File

@ -51,3 +51,4 @@
namespace python = boost::python; namespace python = boost::python;
#include <boost/regex.hpp> #include <boost/regex.hpp>
#include <boost/variant.hpp>

View File

@ -51,24 +51,55 @@ TypedVar::TypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
ULONG64 BaseTypeVariant BasicTypedVar::getValue()
BasicTypedVar::getValue() const
{ {
HRESULT hres;
ULONG64 val = 0; ULONG64 val = 0;
HRESULT hres;
hres = m_dataSpaces->ReadVirtual( m_offset, &val, getSize(), NULL ); hres = m_dataSpaces->ReadVirtual( m_offset, &val, getSize(), NULL );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw MemoryException( m_offset, false ); throw MemoryException( m_offset, false );
return val; if ( m_typeInfo->getName() == "Char" )
return (LONG)*(PCHAR)&val;
if ( m_typeInfo->getName() == "WChar" )
return (LONG)*(PWCHAR)&val;
if ( m_typeInfo->getName() == "Int2B" )
return (LONG)*(PSHORT)&val;
if ( m_typeInfo->getName() == "UInt2B" )
return (ULONG)*(PUSHORT)&val;
if ( m_typeInfo->getName() == "Int4B" )
return *(PLONG)&val;
if ( m_typeInfo->getName() == "UInt4B" )
return *(PULONG)&val;
if ( m_typeInfo->getName() == "Int8B" )
return (LONG64)*(PLONG64)&val;
if ( m_typeInfo->getName() == "UInt8B" )
return (ULONG64)*(PULONG64)&val;
if ( m_typeInfo->getName() == "Long" )
return *(PLONG)&val;
if ( m_typeInfo->getName() == "ULong" )
return *(PULONG)&val;
if ( m_typeInfo->getName() == "Bool" )
return *(bool*)&val;
throw DbgException( "failed get value " );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
ULONG64 BaseTypeVariant PtrTypedVar::getValue()
PtrTypedVar::getValue() const
{ {
HRESULT hres; HRESULT hres;
ULONG64 val = 0; ULONG64 val = 0;

View File

@ -59,14 +59,10 @@ protected:
TypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset ); TypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset );
virtual ULONG64 getValue() const { virtual BaseTypeVariant getValue() {
return m_offset; return m_offset;
} }
virtual void setValue( ULONG64 value) {
throw DbgException("can not change");
}
TypeInfoPtr m_typeInfo; TypeInfoPtr m_typeInfo;
ULONG64 m_offset; ULONG64 m_offset;
@ -87,7 +83,7 @@ public:
return intBase::str(); return intBase::str();
} }
virtual ULONG64 getValue() const; virtual BaseTypeVariant getValue();
}; };
@ -108,7 +104,7 @@ public:
return "PtrTypedVar"; return "PtrTypedVar";
} }
virtual ULONG64 getValue() const; virtual BaseTypeVariant getValue();
}; };

146
test/scripts/intbase.py Normal file
View File

@ -0,0 +1,146 @@
import unittest
import target
from pykd import intBase
class IntBaseTest( unittest.TestCase ):
def testCtor( self ):
a = intBase(0xFF)
a = intBase(0xFFFF)
a = intBase(0xFFFFFFFF)
a = intBase(0x8000000000000000)
a = intBase(0xFFFFFFFFFFFFFFFF)
a = intBase(-20)
a = intBase(-2000)
a = intBase(-200000)
a = intBase(-20000000000)
a = intBase(-0xFFFFFFFFFFFFFFFF )
a = intBase( True )
def testEq( self ):
self.assertTrue( 0xFF == intBase(0xFF) and intBase(0xFF) == 0xFF )
self.assertTrue( 0xFFFF == intBase(0xFFFF) and 0xFFFF == intBase(0xFFFF) )
self.assertTrue( 0xFFFFFFFF == intBase(0xFFFFFFFF) and intBase(0xFFFFFFFF) == 0xFFFFFFFF )
self.assertTrue( 0x8000000000000000 == intBase(0x8000000000000000) )
self.assertTrue( 0xFFFFFFFFFFFFFFFF == intBase(0xFFFFFFFFFFFFFFFF) )
self.assertTrue( -20 == intBase(-20) )
self.assertTrue( -2000 == intBase(-2000) )
self.assertTrue( -20000000000 == intBase(-20000000000) )
self.assertTrue( -0x8000000000000000 == intBase(-0x8000000000000000) )
self.assertTrue( intBase(0x20L) == intBase(0x20) )
self.assertTrue( True == intBase(True) )
self.assertTrue( False == intBase(0) )
self.assertTrue( True == intBase(1) )
def testNe( self ):
self.assertTrue( 0xFE != intBase(0xFF) )
self.assertTrue( 0xFF00 != intBase(0xFFFF) )
self.assertTrue( 0xFFFFFF88 != intBase(0xFFFFFFFF) )
self.assertTrue( 0x8000000000000000 - 1 != intBase(0x8000000000000000) )
self.assertTrue( 0xFFFFFFFFFFFFFFFF - 1 != intBase(0xFFFFFFFFFFFFFFFF) )
self.assertTrue( -20 + 1 != intBase(-20) )
self.assertTrue( -2000 + 1 != intBase(-2000) )
self.assertTrue( -20000000000 + 1 != intBase(-20000000000) )
self.assertTrue( -0x8000000000000000 - 1 != intBase(-0x8000000000000000) )
def testLtGt( self ):
self.assertTrue( 0xFE < intBase(0xFF) and intBase(0xFE) < 0xFF )
self.assertFalse( -99 < intBase(-100) and intBase(-99) < - 100 )
self.assertTrue( 0xFFFFFFFFFFFFFFFE < intBase(0xFFFFFFFFFFFFFFFF) )
self.assertFalse(0xFFFFFFFFFFFFFFFF < intBase(0xFFFFFFFFFFFFFFFE) )
self.assertTrue( intBase(0xFFFFFFFFFFFFFFFE) < 0xFFFFFFFFFFFFFFFF )
def testLeGe( self ):
self.assertTrue( 0xFE <= intBase(0xFF) and intBase(0xFE) <= 0xFF )
self.assertTrue( 0xFF <= intBase(0xFF) )
self.assertFalse( -99 <= intBase(-100) and intBase(-99) <= - 100 )
self.assertTrue( 0xFFFFFFFFFFFFFFFE <= intBase(0xFFFFFFFFFFFFFFFF) )
self.assertFalse(0xFFFFFFFFFFFFFFFF <= intBase(0xFFFFFFFFFFFFFFFE) )
self.assertTrue( intBase(0xFFFFFFFFFFFFFFFF) <= 0xFFFFFFFFFFFFFFFF )
def testAdd( self ):
self.assertEqual( 10, intBase(5) + 5 )
self.assertEqual( 10, 5 + intBase(5) )
a = 10
a += intBase(10)
self.assertEqual( 20, a )
self.assertEqual( -20, intBase(-10) + (-10) )
self.assertEqual( 10, intBase(-10) + 20 )
self.assertEqual( 0x7fffffffffffffff + 1, intBase(0x7fffffffffffffff) + 1)
self.assertEqual( -0x8000000000000000 + 10, intBase(-0x8000000000000000) + 10 )
self.assertEqual( 0, intBase(-0x8000000000000000) + 0x8000000000000000 )
def testSub( self ):
self.assertEqual( 0, intBase(5) - 5 )
self.assertEqual( 10, 15 - intBase(5) )
a = 10
a -= intBase(5)
self.assertEqual( 5, a )
self.assertEqual( -20, intBase(-10) -10 )
self.assertEqual( -10, 10 - intBase(20) )
self.assertEqual( -0xFFFFFFFF - 1, intBase(-0xFFFFFFFF) - 1 )
def testMul( self ):
self.assertEqual( 4, intBase(2) * 2 )
self.assertEqual( 4, 2 * intBase(2) )
self.assertEqual( -4, 2 * intBase(-2) )
self.assertEqual( 4, -2 * intBase(-2) )
self.assertEqual( 0x7fffffffffffffff * 2, intBase(0x7fffffffffffffff) * 2)
self.assertEqual( 0x80000000*2, intBase(0x80000000)*2 )
self.assertEqual( -0x80000000*2, 2 * intBase(-0x80000000))
def testDiv( self ):
self.assertEqual( 1, intBase(2) / 2 )
self.assertEqual( 2, 5 / intBase(2) )
self.assertEqual( -1, 2 / intBase(-2) )
self.assertEqual( 1, -2 / intBase(-2) )
try:
-2 / intBase(0)
self.assertTrue( False )
except ZeroDivisionError:
self.assertTrue( True )
try:
intBase(2)/0
self.assertTrue( False )
except ZeroDivisionError:
self.assertTrue( True )
def testMod( self ):
self.assertEqual( 1, intBase(3) % 2 )
self.assertEqual( 0, intBase(3) % 3 )
self.assertEqual( 1, 3 % intBase(2) )
self.assertEqual( 0, 3 % intBase(3) )
def testShift( self ):
self.assertEqual( 0xFFFFFFFF >> 8, intBase(0xFFFFFFFF) >> 8 )
self.assertEqual( 0x00FFFFFF << 8, intBase(0x00FFFFFF) << 8 )
self.assertEqual( 0xFFFFFFFF >> 8, 0xFFFFFFFF >> intBase(8) )
self.assertEqual( 0x00FFFFFF << 8, 0x00FFFFFF << intBase(8) )
def testAnd( self ):
self.assertEqual( 0xFFFFFFFF & 0xFFFF, intBase(0xFFFFFFFF) & 0xFFFF )
self.assertEqual( 0xFFFFFFFF & 0xFFFF, 0xFFFFFFFF & intBase(0xFFFF) )
self.assertEqual( -0xFFFFFFFF & 0xFFFF, intBase(-0xFFFFFFFF) & 0xFFFF )
self.assertEqual( -0xFFFFFFFF & 0xFFFF, -0xFFFFFFFF & intBase(0xFFFF) )
def testOr( self ):
self.assertEqual( 0xFFFF0000 | 0xFFFF, intBase(0xFFFF0000) | 0xFFFF )
self.assertEqual( 0xFFFF0000 | 0xFFFF, 0xFFFF0000 | intBase(0xFFFF) )
self.assertEqual( -0xFFFF0000 | 0xFFFF, intBase(-0xFFFF0000) | 0xFFFF )
self.assertEqual( -0xFFFF0000 | 0xFFFF, -0xFFFF0000 | intBase(0xFFFF) )
def testXor( self ):
self.assertEqual( 0xFFFFFFFF ^ 0xFFFF, intBase(0xFFFFFFFF) ^ 0xFFFF )
self.assertEqual( 0xFFFFFFFF ^ 0xFFFF, 0xFFFFFFFF ^ intBase(0xFFFF) )
self.assertEqual( -0xFFFFFFFF ^ 0xFFFF, intBase(-0xFFFFFFFF) ^ 0xFFFF )
self.assertEqual( -0xFFFFFFFF ^ 0xFFFF, -0xFFFFFFFF ^ intBase(0xFFFF) )
def testUnary( self ):
self.assertEqual( -0xFFFFFFFF, -intBase(0xFFFFFFFF) )
self.assertEqual( 0xFFFFFFFF, +intBase(0xFFFFFFFF) )
self.assertEqual( 0, ~intBase(0xFFFFFFFF) )

View File

@ -21,6 +21,7 @@ import clienttest
import eventtest import eventtest
import typedvar import typedvar
import memtest import memtest
import intbase
def getTestSuite( singleName = "" ): def getTestSuite( singleName = "" ):
if singleName == "": if singleName == "":
@ -34,6 +35,7 @@ def getTestSuite( singleName = "" ):
unittest.TestLoader().loadTestsFromTestCase( clienttest.DbgClientTest ), unittest.TestLoader().loadTestsFromTestCase( clienttest.DbgClientTest ),
unittest.TestLoader().loadTestsFromTestCase( eventtest.EventTest ), unittest.TestLoader().loadTestsFromTestCase( eventtest.EventTest ),
unittest.TestLoader().loadTestsFromTestCase( memtest.MemoryTest ), unittest.TestLoader().loadTestsFromTestCase( memtest.MemoryTest ),
unittest.TestLoader().loadTestsFromTestCase( intbase.IntBaseTest ),
] ) ] )
else: else:
return unittest.TestSuite( unittest.TestLoader().loadTestsFromName( singleName ) ) return unittest.TestSuite( unittest.TestLoader().loadTestsFromName( singleName ) )
@ -52,7 +54,7 @@ if __name__ == "__main__":
target.module.reload(); target.module.reload();
suite = getTestSuite() suite = getTestSuite()
#suite = getTestSuite( "typedvar.TypedVarTest" ) #suite = getTestSuite( "typedvar.TypedVarTest.testStruct" )
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( suite ) unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( suite )

View File

@ -52,14 +52,14 @@ class TypedVarTest( unittest.TestCase ):
self.assertEqual( 0, tv.m_arrayField[0] ) self.assertEqual( 0, tv.m_arrayField[0] )
self.assertEqual( 2, tv.m_arrayField[1] ) self.assertEqual( 2, tv.m_arrayField[1] )
self.assertEqual( 3, tv.m_noArrayField ) self.assertEqual( 3, tv.m_noArrayField )
self.assertNotEqual( -1, long(tv.m_arrayField[0]) ) self.assertNotEqual( -1, tv.m_arrayField[0] )
self.assertNotEqual( 0, tv.m_noArrayField ) self.assertNotEqual( 0, tv.m_noArrayField )
def testGlobalVar(self): def testGlobalVar(self):
self.assertEqual( 4, target.module.typedVar( "g_ulongValue" ) ) self.assertEqual( 4, target.module.typedVar( "g_ulongValue" ) )
self.assertEqual( 0x80000000, target.module.typedVar( "ulongArray" )[3] ) self.assertEqual( 0x80000000, target.module.typedVar( "ulongArray" )[3] )
self.assertEqual( 0x8000000000000000, target.module.typedVar( "ulonglongArray" )[3] ) self.assertEqual( 0x8000000000000000, target.module.typedVar( "ulonglongArray" )[3] )
self.assertEqual( -100000, int(target.module.typedVar( "longArray" )[3]) ) self.assertEqual( -100000, target.module.typedVar( "longArray" )[3])
self.assertEqual( -10000000000, long(target.module.typedVar( "longlongArray" )[4]) ) self.assertEqual( -10000000000, target.module.typedVar( "longlongArray" )[4])
self.assertEqual( target.module.g_structTest, target.module.typedVar( "g_structTestPtr" ) ) self.assertEqual( target.module.g_structTest, target.module.typedVar( "g_structTestPtr" ) )