-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+
cxx/ClassObject.cxx
: +classObjectTests()
Is followup to: commit 940915427d5a86c347a973fea4f9b73c9cc37ef9 (?`cxx/ClassObject.hxx`: +`SUSUWU_VIRTUAL_DEFAULTS), the first commit with known good {`Class`, `Object`} operators. Has to do with issues: #10 (Java port), #14 (more unit tests). ?`cxx/ClassObject.*xx`: +`classObjectTestValid()`, +`classObjectTestCommutative()`, +`classObjectTestMatch()`, +`classObjectTestMismatch()`; helper functions for `classObjectTests()`. +`classObjectTests()`; tests {`Class`, `Object`}::{`getObjectSize`, `getName`, `operator==`, `operator!=`, `hasImplementation`, `isInitialized`}. +`classObjectTestsNoexcept()`; `templateCatchAll` wrap for `classObjectTests()`. ?`build.sh`: ?`FLAGS_SPECIAL`: +`-DSUSUWU_VIRTUAL_VTABLE_COMPARISON`; "Error: classObjectTestMatch() { if(class1->operator!=(*class2 /*Susuwu::Object*/)) { /* `Susuwu::Object::operator!=` false negative. */ } }]" workaround. TODO: fix without workaround. ?`cxx/main.hxx`: +`susuwuUnitTestsClassObjectBit`; indicates error in `classSysObjectTests()`. ?`cxx/main.cxx`: ?`unitTestsCxx`; test `classSysObjectTests()`. ?`posts/VirusAnalysis.md`: include `cxx/main.*xx`; the virtuals (from `cxx/ClassObjects.hxx`) are not used enough to include.
- Loading branch information
1 parent
fc90b89
commit 758cd85
Showing
6 changed files
with
180 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* Dual licenses: choose "Creative Commons" or "Apache 2" (allows all uses) */ | ||
#ifndef INCLUDES_cxx_ClassObject_cxx | ||
#define INCLUDES_cxx_ClassObject_cxx | ||
#include "Macros.hxx" /* SUSUWU_ERROR */ | ||
#include "ClassObject.hxx" /* Class Object SUSUWU_CLASS_DEFAULTS SUSUWU_VIRTUAL_EQUALS_USE_ADDRESSES SUSUWU_VIRTUAL_VTABLE_COMPARISON SUSUWU_VIRTUAL_DEFAULTS */ | ||
#include "ClassSys.hxx" /* templateCatchAll */ | ||
//#include <cassert> /* assert */ | ||
#include <cctype> /* size_t */ | ||
//#include <cstring> /* memcmp */ | ||
//#include <memory> /* std::unique_ptr std::make_unique */ | ||
//#include <stdexcept> /* std::runtime_error */ | ||
//#include <string> /* std::string */ | ||
namespace Susuwu { | ||
class SubClass : public Class { SUSUWU_CLASS_DEFAULTS(SubClass) }; | ||
class SubClassWithMemberObject : public Class { public: SUSUWU_CLASS_DEFAULTS(SubClassWithMemberObject) bool memberObject = true; }; | ||
class SubObject : public Object { SUSUWU_VIRTUAL_DEFAULTS(SubObject) }; | ||
class SubObjectWithMemberObject : public Object { public: SUSUWU_VIRTUAL_DEFAULTS(SubObjectWithMemberObject) bool memberObject = true;}; | ||
const bool classObjectTestsNoexcept() SUSUWU_NOEXCEPT {return templateCatchAll(classObjectTests, "classObjectTests()");} | ||
static const bool classObjectTestValid(const Class *clas) { | ||
if(clas->getObjectSize() != sizeof(*clas)) { | ||
SUSUWU_NOTICE("classObjectTestValid() { if(clas->sizeo() != sizeof(*clas)) { /* `" + clas->getName() + "::getObjectSize()` != `sizeof(" + clas->getName() + ")`. */ } }"); | ||
} | ||
return true; | ||
} | ||
static const bool classObjectTestCommutative(const Class *class1, const Class *class2) { /* TODO: call this "Symmetric"? */ | ||
bool result = true /* TODO: classObjectTestValid(class1) && classObjectTestValid(class2) */; | ||
if(class1->operator!=(*class2) != class2->operator!=(*class1)) { | ||
SUSUWU_ERROR("classObjectTestCommutative() { if(class1->operator!=(*class2) != class2->operator!=(*class1)) { /* `" + class1->getName() + "::operator!=` not commutative to `" + class2->getName() + "::operator!=`. */ } }"); | ||
result = false; | ||
} | ||
if(class1->operator==(*class2) != class2->operator==(*class1)) { | ||
SUSUWU_ERROR("classObjectTestCommutative() { if(class1->operator==(*class2) != class2->operator==(*class1)) { /* `" + class1->getName() + "::operator==` not commutative to `" + class2->getName() + "::operator==`. */ } }"); | ||
result = false; | ||
} | ||
if(class1->operator==(*class2) == class1->operator!=(*class2)) { | ||
SUSUWU_ERROR("classObjectTestCommutative() { if(class1->operator==(*class2/*" + class2->getName() + "*/ == class1->operator!=(*class2)) { /* `" + class1->getName() + "::operator==` not anticommuttative to `" + class1->getName() + "::operator!=`. */ } }"); | ||
result = false; | ||
} | ||
return result; | ||
} | ||
static const bool classObjectTestMatch(const Class *class1, const Class *class2) { | ||
bool result = classObjectTestCommutative(class1, class2); | ||
if(class1->operator!=(*class2)) { | ||
SUSUWU_ERROR("classObjectTestMatch() { if(class1->operator!=(*class2 /*" + class2->getName() + "*/)) { /* `" + class1->getName() + "::operator!=` false negative. */ } }"); | ||
result = false; | ||
} | ||
return result; | ||
} | ||
static const bool classObjectTestMismatch(const Class *class1, const Class *class2) { | ||
bool result = classObjectTestCommutative(class1, class2); | ||
if(class1->operator==(*class2)) { | ||
SUSUWU_ERROR("classObjectTestMismatch() { if(class1->operator==(*class2 /*" + class2->getName() + "*/)) { /* `" + class1->getName() + "::operator==` false positive. */ } }"); | ||
result = false; | ||
} | ||
if(class1->getName() == class2->getName()) { | ||
SUSUWU_ERROR(std::string("classObjectTestMismatchs() { if(class1->getName() == class2->getName()) { /* `") + typeid(class1).name() + "::getName() == \"" + class1->getName() + "\"`, but also `" + typeid(class2).name() + "::getName() == \"" + class2->getName() + "\"` */ } }"); | ||
result = false; | ||
} | ||
return result; | ||
} | ||
const bool classObjectTests() { | ||
bool result = true; | ||
|
||
const Class *classPtr = new Class(), | ||
*objectPtr = new Object(), | ||
*subClassPtr = new SubClass(), | ||
*subObjectPtr = new SubObject(), | ||
*subClassWithMemberObjectPtr = new SubClassWithMemberObject(), | ||
*subObjectWithMemberObjectPtr = new SubObjectWithMemberObject(); | ||
const Class class2 = Class(); | ||
const Object object2 = Object(); | ||
|
||
result &= classObjectTestMatch(classPtr, classPtr) /* reflexive */; | ||
result &= classObjectTestMatch(subClassPtr, subClassPtr) /* reflexive */; | ||
result &= classObjectTestMatch(subClassWithMemberObjectPtr, subClassWithMemberObjectPtr) /* reflexive */; | ||
result &= classObjectTestMatch(objectPtr, objectPtr) /* reflexive */; | ||
result &= classObjectTestMatch(subObjectPtr, subObjectPtr) /* reflexive */; | ||
result &= classObjectTestMatch(subObjectWithMemberObjectPtr, subObjectWithMemberObjectPtr) /* reflexive */; | ||
#ifdef SUSUWU_VIRTUAL_EQUALS_USE_ADDRESSES /* If you interpret `Java`'s standard as "Addresses must match". */ | ||
result &= classObjectTestMismatch(classPtr, &class2); | ||
result &= classObjectTestMismatch(objectPtr, &object2); | ||
#else /* SUSUWU_VIRTUAL_EQUALS_USE_ADDRESSES else */ | ||
SUSUWU_PRAGMA(message("TODO: SUSUWU_VIRTUAL_EQUALS_USE_ADDRESSES")) | ||
result &= classObjectTestMatch(classPtr, &class2) /* reflexive */; | ||
result &= classObjectTestMatch(objectPtr, &object2) /* reflexive */; | ||
#endif /* SUSUWU_VIRTUAL_EQUALS_USE_ADDRESSES else */ | ||
#ifdef SUSUWU_VIRTUAL_VTABLE_COMPARISON /* If you interpret `Java`'s standard as "`typeid` must match". */ | ||
SUSUWU_PRAGMA(message("Notice: SUSUWU_VIRTUAL_VTABLE_COMPARISON")) | ||
result &= classObjectTestMismatch(classPtr, subClassPtr); | ||
result &= classObjectTestMismatch(classPtr, objectPtr); | ||
result &= classObjectTestMismatch(classPtr, subObjectPtr); | ||
result &= classObjectTestMismatch(classPtr, &object2); | ||
result &= classObjectTestMismatch(objectPtr, subObjectPtr); | ||
result &= classObjectTestMismatch(objectPtr, &class2); | ||
#else /* SUSUWU_VIRTUAL_VTABLE_COMPARISON else */ | ||
result &= classObjectTestMatch(classPtr, subClassPtr) /* transitive */; | ||
result &= classObjectTestMatch(classPtr, objectPtr) /* transitive */; | ||
result &= classObjectTestMatch(classPtr, subObjectPtr) /* transitive */; | ||
result &= classObjectTestMatch(classPtr, &object2) /* transitive */; | ||
result &= classObjectTestMatch(objectPtr, &class2) /* transitive */; | ||
result &= classObjectTestMatch(objectPtr, subObjectPtr) /* transitive */; | ||
#endif /* SUSUWU_VIRTUAL_VTABLE_COMPARISON else */ | ||
result &= classObjectTestMismatch(classPtr, subObjectWithMemberObjectPtr) /* `getObjectSize()` mismatch */; | ||
result &= classObjectTestMismatch(classPtr, subClassWithMemberObjectPtr) /* `getObjectSize()` mismatch */; | ||
result &= classObjectTestMismatch(subClassPtr, subObjectWithMemberObjectPtr) /* `getObjectSize()` mismatch */; | ||
result &= classObjectTestMismatch(subClassPtr, subClassWithMemberObjectPtr) /* `getObjectSize()` mismatch */; | ||
result &= classObjectTestMismatch(objectPtr, subClassWithMemberObjectPtr) /* `getObjectSize()` mismatch */; | ||
result &= classObjectTestMismatch(objectPtr, subObjectWithMemberObjectPtr) /* `getObjectSize()` mismatch */; | ||
result &= classObjectTestMismatch(subObjectPtr, subClassWithMemberObjectPtr) /* `getObjectSize()` mismatch */; | ||
result &= classObjectTestMismatch(subObjectPtr, subObjectWithMemberObjectPtr) /* `getObjectSize()` mismatch */; | ||
if(classPtr->getName() != class2.getName()) { | ||
SUSUWU_ERROR("classObjectTests() { if(classPtr->getName() != class2.getName()) { /* `Class::getName()` virtual error */ } }"); | ||
result = false; | ||
} | ||
if(objectPtr->getName() != object2.getName()) { | ||
SUSUWU_ERROR("classObjectTests() { if(objectPtr->getName() != object2.getName()) { /* `Object::getName()` virtual error */ } }"); | ||
result = false; | ||
} | ||
|
||
if(!object2.hasImplementation()) { | ||
SUSUWU_ERROR("classObjectTests() { if(!object2.hasImplementation()) { /* `Object::hasImplementation` false negative */ } }"); | ||
result = false; | ||
} | ||
if(!object2.isInitialized()) { | ||
SUSUWU_ERROR("classObjectTests() { if(!object2.hasIsInitialized()) { /* `Object::hasImplementation` false negative */ } }"); | ||
result = false; | ||
} | ||
|
||
delete subObjectWithMemberObjectPtr; | ||
delete subClassWithMemberObjectPtr; | ||
delete subObjectPtr; | ||
delete subClassPtr; | ||
delete objectPtr; | ||
delete classPtr; | ||
return result; | ||
} | ||
|
||
}; /* namespace Susuwu */ | ||
#endif /* ndef INCLUDES_cxx_ClassObject_cxx */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters