Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » CHECK macro
CHECK macro [message #5993] Fri, 27 October 2006 03:26 Go to next message
exolon is currently offline  exolon
Messages: 62
Registered: July 2006
Location: 53'21N 6'18W
Member
Hi, I was wondering if anyone can explain the purpose of the CHECK macro defined in Core/Diag.h? Is it an assertion macro?

It's a very generic name, and since macros seem to have no scope or namespaces (I don't know much about preprocessor stuff since I don't use it much), it conflicts in my case with the unit testing library I use (UnitTest++). This means I either have to rename the macro in the testing library which doesn't seem right, or rename the one in Diag.h and wherever it's used. This is what I've done before, but I don't like having to do it every time I move to the next version of UPP. It causes trouble when I include Core/Core.h to use the String class, for example.

Does anyone have any ideas about handling this more easily?
Re: CHECK macro [message #5994 is a reply to message #5993] Fri, 27 October 2006 03:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
It is similar to ASSERT, but expression gets evaluated even in release mode (therefore you do not lose desired side effects - e.g. you can use CHECK to test the return code of some routine. If you would do it with ASSERT, routine would not get called in release mode).

I guess the simple thing to do is #undef CHECK before including your unit testing stuff.

Mirek

P.S.: Unit testing is on my radar for future U++ development, perhaps you could share your opinions in develeopment forum...
Re: CHECK macro [message #5995 is a reply to message #5994] Fri, 27 October 2006 04:05 Go to previous messageGo to next message
exolon is currently offline  exolon
Messages: 62
Registered: July 2006
Location: 53'21N 6'18W
Member
luzr wrote on Fri, 27 October 2006 02:41

It is similar to ASSERT, but expression gets evaluated even in release mode (therefore you do not lose desired side effects - e.g. you can use CHECK to test the return code of some routine. If you would do it with ASSERT, routine would not get called in release mode).

So it's a sort of design-by-contract "defensive programming" thing?

luzr wrote on Fri, 27 October 2006 02:41

I guess the simple thing to do is #undef CHECK before including your unit testing stuff.

Well, doing this caused a lot of errors since CHECK was redefined and some code in Core is trying to use it. It's not a big deal, I made a terrible sed script to do some of the replacements. And if, as you say, unit testing is a future consideration for U++ (a very good thing!!), I'll participate as much as my limited experience allows on that topic. Smile
Re: CHECK macro [message #5999 is a reply to message #5995] Fri, 27 October 2006 08:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Oh, I was thinking about something like:

#include <CtrlLib/CtrlLib.h>

#undef CHECK

#include <unittest.h>


should not cause any problems with U++....

Mirek
Re: CHECK macro [message #6008 is a reply to message #5993] Fri, 27 October 2006 23:11 Go to previous messageGo to next message
exolon is currently offline  exolon
Messages: 62
Registered: July 2006
Location: 53'21N 6'18W
Member
Hmm, you're right Mirek, that seems to work fine now. I was sure I tried this before and it caused many errors, so I renamed it in uppsrc instead.

However, with upp610-dev2 undefining CHECK before the unittest library does indeed work fine.

// trivial example
#include <Palindrome/Palindrome.h>
#undef CHECK
#include <UnitTest++.h>

TEST(CanInstantiate) {
	String test = "abc";
	Palindrome palindrome(test);
}

TEST(FalseForNonPalindrome) {
	String test = "abc";
	Palindrome palindrome(test);
	CHECK_EQUAL(palindrome.isPalindrome(), false);
}

TEST(TrueForPalindrome) {
	String test = "amanaplanacanalpanama";
	Palindrome palindrome(test);
	CHECK_EQUAL(palindrome.isPalindrome(), true);
}

int main(int, char **) {
	return UnitTest::RunAllTests();
}

Thanks, that saves me trouble Smile
Re: CHECK macro [message #6016 is a reply to message #6008] Sat, 28 October 2006 16:35 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
exolon wrote on Fri, 27 October 2006 17:11

Hmm, you're right Mirek, that seems to work fine now. I was sure I tried this before and it caused many errors, so I renamed it in uppsrc instead.


I bet you tried #undef before #include of U++ headers Smile

Mirek
Previous Topic: strcmp() works with String?
Next Topic: dynamic loading of Ctrls using dli?
Goto Forum:
  


Current Time: Tue Apr 16 21:05:10 CEST 2024

Total time taken to generate the page: 0.64150 seconds