Copyright 2019, Erik N. Johnson
This software is distributed under the MIT 3-clause license (../License.ENJ).
This test file tests the basic autoObject mixin mechanism, using mostly the uint8_t handler type. It tests single and multi-field objects, but only using scalar elements (no arrays, enums, bitfields, etc.). Individual mixin type classes are fully tested in other test files.
Preamble for all tests
package require tcltest
namespace import ::tcltest::*
lappend auto_path ".."
package require autoObject
Series of tests creating and testing the functions of an object with a single defined field. Tests interactions between base class and field mixin classes, tests scalar Dispatch, and happens to test the simplest of the data types, uint8_t. Also tests field-direct invocation, and using that tests the return value of fromList with excess list data.
puts ""
puts ""
puts "\tScalar Field Tests - 1 Field Object"
puts ""
test oneField_create {Create object with one uint8_t field} -body {
set oneFieldObj [autoObject new {
firstField {0 1 uint8_t 0 }
}]
} -match glob -result "::oo::Obj*"
test oneField_validate {1 field object: validate} -body {
$oneFieldObj validate
} -constraints {
$::AutoObject::AUTOOBJECT_VERSION >= 1.0
} -result true
test oneField_configInit {1 field object: config -initialized} -body {
$oneFieldObj configure -initialized true
} -result ""
test oneField_emptyGet {1 field object: get with no args} -body {
$oneFieldObj get
} -result {firstField 0}
test oneField_toString {1 field object: toString} -body {
$oneFieldObj toString
} -result " firstField: 0 "
test oneField_getField {1 field object: get firstField} -body {
$oneFieldObj get firstField
} -result "0"
test oneField_toList {1 field object: toList} -body {
$oneFieldObj toList
} -result {0}
test oneField_setNoArgs {1 field object: set with no args} -body {
$oneFieldObj set
} -result ""
test oneField_fromList {1 field object: fromList} -body {
$oneFieldObj fromList {123}
} -result ""
test oneField_toString {1 field object: toString} -body {
$oneFieldObj toString
} -result " firstField: 123"
Because fromList is forwarded down to the field, it tests the mixin class action in isolation, not as part of the larger object mechanism. This lets us test the field-only behavior that each field cuts its own data off the input data list and returns whatever's left (in this case, 456 (which is too large a number to fit in the data type but must not be corrupted) ).
test oneField_fwdFmListXtraData {
1 field object: forwarding fromlist from the field to test extra list data
} -body {
$oneFieldObj firstField fromList {210 456}
} -result 456
test oneField_toList2 {1 field object: toList to check new value} -body {
$oneFieldObj toList
} -result 210
test oneField_toString2 {1 field object: toString} -body {
$oneFieldObj toString
} -result " firstField: 210"
Series of tests creating and testing the functions of an object with two fields. Starts a new series by creating a new object. Tests multi-field interactions and tests signed number handling.
puts ""
puts ""
puts "\tScalar Field Tests - 2 Field Object"
puts ""
test twoField_create {2 Field object: create} -body {
set twoFieldObj [autoObject new {
variable_length_object 1
firstField {0 1 uint8_t 0 }
secondField {1 1 int8_t -1 }
}]
} -match glob -result "::oo::Obj*"
Configure as initialized for later tests
$twoFieldObj configure -initialized true
test twoField_toString {2 Field object: toString} -body {
$twoFieldObj toString
} -result "\
\ firstField: 0 \n\
\ secondField: -1 "
test twoField_toList {2 Field object: toList} -body {
$twoFieldObj toList
} -result {0 255}
test twoField_emptyGet {2 Field object: get with empty args} -body {
$twoFieldObj get
} -result "firstField 0 secondField -1"
test twoField_fromList {2 Field object: fromList} -body {
$twoFieldObj fromList {210 -5}
} -result ""
test twoField_get2nd {2 Field object: get 2nd field, verify fromList} -body {
$twoFieldObj get secondField
} -result -5
test twoField_toString2 {2 Field object: toString, 2nd data set} -body {
$twoFieldObj toString
} -result "\
\ firstField: 210\n\
\ secondField: -5 "
test twoField_toList2 {2 Field object: toList with second data set} -body {
$twoFieldObj toList
} -result {210 251}
test twoField_fromShortList {2 Field object: fromList, short data list} -body {
$twoFieldObj fromList {123}
} -result ""
test twoField_toString3 {2 Field object: toString, 3rd data set} -body {
$twoFieldObj toString
} -result "\
\ firstField: 123\n\
\ secondField: -5 "
Series of tests creating and testing the functions of an object with multiple fields including big-endian and little-endian 16-bit data fields. Starts a new series by creating a new object. The data types are fully tested elsewhere; this set of tests is looking for interactions between multiple data types.
puts ""
puts ""
puts "\t16 Bit Field Object tests"
puts ""
test 16bit_create {16 bit field object: create} -body {
set obj3 [autoObject new {
firstField {0 1 uint8_t 0 }
secondField {1 1 int8_t -1 }
thirdField {2 2 uint16_t 800 }
fourthField {4 2 int16_bt -4000 }
}]
} -match glob -result "::oo::Obj*"
Configure the object as initialized
$obj3 configure -initialized true
test 16bit_toString {16 bit field object: toString} -body {
$obj3 toString
} -result "\
\ firstField: 0 \n\
\ secondField: -1 \n\
\ thirdField: 800 \n\
\ fourthField: -4000"
test 16bit_toList {16 bit field object: toList} -body {
$obj3 toList
} -result {0 255 32 3 240 96}
test 16bit_emptyGet {16 bit field object: get with empty args} -body {
$obj3 get
} -result {firstField 0 secondField -1 thirdField 800 fourthField -4000}
note that the two 16-bit fields get the same data, {5 10}, but they get different values because they have different endianness.
test 16bit_fromList {16 bit field object: fromList} -body {
$obj3 fromList {210 -5 5 10 5 10}
} -result ""
test 16bit_toString2 {16 bit field object: toString, data set 2} -body {
$obj3 toString
} -result "\
\ firstField: 210\n\
\ secondField: -5 \n\
\ thirdField: 2565 \n\
\ fourthField: 1290 "
test 16bit_get3rd {16 bit field object: get 3rd field, 2nd data set} -body {
$obj3 get thirdField
} -result 2565
test 16bit_toList2 {16 bit field object: toList, data set 2} -body {
$obj3 toList
} -result {210 251 5 10 5 10}
Series of tests creating and testing the functions of an object with a mixin class that inherits from other mixin classes that are not explicitly included in this object, including multiple inheritance - int16_bt inherits from uint16_t via int16_t AND via uint16_bt. Starts a new series by creating a new object.
puts ""
puts ""
puts "\tMixin superclass inheritance tests"
puts ""
Test inheritance on mixin classes , both of which are superclasses.
test inherit_create {mixin inheritance object: create} -body {
set obj4 [autoObject new {
myField {0 2 int16_bt -4000 }
}]
} -match glob -result "::oo::Obj*"
$obj4 configure -initialized true
test inherit_emptyGet {mixin inheritance object: get with no args} -body {
$obj4 get
} -result {myField -4000}
test inherit_toString {mixin inheritance object: toString} -body {
$obj4 toString
} -result " myField: -4000"
test inherit_setVal {mixin inheritance object: set} -body {
$obj4 set myField -12345
} -result ""
test inherit_toList {mixin inheritance object: toList} -body {
$obj4 toList
} -result {207 199}
test inherit_fromList {mixin inheritance object: fromList} -body {
$obj4 fromList {10 5}
} -result ""
test inherit_getField {mixin inheritance object: get myField} -body {
$obj4 get myField
} -result 2565
test inherit_ {mixin inheritance object: } -body {} -result
cleanupTests