Author: baby-guest Date: 2008-02-20 08:33:57 +0000 (Wed, 20 Feb 2008) New Revision: 5864
Added: software/ui/src/Makefile.test Removed: software/ui/src/filter_test.cpp software/ui/src/taghandler_test.cpp Modified: software/ui/README software/ui/src/CuTest.h software/ui/src/CuTest.sh software/ui/src/filter.cpp software/ui/src/filter.h software/ui/src/goplay.cpp software/ui/src/taghandler.cpp software/ui/src/taghandler.h Log: Added better support for unit tests Improved functions for printing debug messages (now they should be able to print in any stream, not just in std::cerr) Modified: software/ui/README =================================================================== --- software/ui/README 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/README 2008-02-20 08:33:57 UTC (rev 5864) @@ -58,6 +58,6 @@ wget http://popcon.debian.org/all-popcon-results.txt.gz ept-cache reindex -Then you can finally run ./games +Then you can finally run ./goplay Enjoy! Modified: software/ui/src/CuTest.h =================================================================== --- software/ui/src/CuTest.h 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/CuTest.h 2008-02-20 08:33:57 UTC (rev 5864) @@ -28,6 +28,8 @@ extern "C" { #endif /* __cplusplus */ +#define TEST_FUNCTION extern "C" void + #include <setjmp.h> #include <stdarg.h> Modified: software/ui/src/CuTest.sh =================================================================== --- software/ui/src/CuTest.sh 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/CuTest.sh 2008-02-20 08:33:57 UTC (rev 5864) @@ -35,7 +35,7 @@ ' -cat $FILES | grep '^void Test' | +cat $FILES | grep '^TEST_FUNCTION Test' | sed -e 's/(.*$//' \ -e 's/$/(CuTest*);/' \ -e 's/^/extern /' @@ -49,8 +49,9 @@ CuSuite* suite = CuSuiteNew(); ' -cat $FILES | grep '^void Test' | +cat $FILES | grep '^TEST_FUNCTION Test' | sed -e 's/^void //' \ + -e 's/^TEST_FUNCTION //' \ -e 's/(.*$//' \ -e 's/^/ SUITE_ADD_TEST(suite, /' \ -e 's/$/);/' @@ -66,5 +67,6 @@ int main(void) { RunAllTests(); + return 0; } ' Added: software/ui/src/Makefile.test =================================================================== --- software/ui/src/Makefile.test (rev 0) +++ software/ui/src/Makefile.test 2008-02-20 08:33:57 UTC (rev 5864) @@ -0,0 +1,27 @@ +OBJS= test_aux.o test_Engine.o test_Environment.o test_filter.o \ + test_goplay.o test_pkgbrowser.o test_taghandler.o \ + test_ui.o test_windows.o CuTest.o test_main.o + +CFLAGS= -O2 -g -I.. -I/usr/include/tagcoll-2.0.7 `fltk-config --cxxflags --use-images` -Wall +LDFLAGS= -lept -lept-core -lapt-pkg -lxapian -ltagcoll2 -lz -lwibble `fltk-config --ldflags --use-images` + +test: $(OBJS) + g++ -o $@ $(LDFLAGS) $+ + +test_main.c: + sh CuTest.sh > $@ + +test_main.o: test_main.c + gcc -o $@ $(CFLAGS) -DUNIT_TEST -c $+ + +test_%.o: %.cpp + g++ -o $@ $(CFLAGS) -DUNIT_TEST -c $+ + +%.o: %.cpp + g++ -o $@ $(CFLAGS) -DUNIT_TEST -c $+ + +%.o: %.c + gcc -o $@ $(CFLAGS) -DUNIT_TEST -c $+ + +clean: + rm -f test test_main.c test_*.o Modified: software/ui/src/filter.cpp =================================================================== --- software/ui/src/filter.cpp 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/filter.cpp 2008-02-20 08:33:57 UTC (rev 5864) @@ -19,6 +19,10 @@ #include "filter.h" #include "taghandler.h" +#ifdef UNIT_TEST +#include "CuTest.h" +#endif + #include <string> #include <ept/debtags/tag.h> @@ -172,7 +176,7 @@ FilterTagHandler::Result t; // unsigned int i = 0; -// tagdata.PrintAll(); +// tagdata.PrintAll(std::cerr); for (TagSet::const_iterator i = tags.begin(); i != tags.end(); ++i) { std::string name = i->fullname(); @@ -186,9 +190,9 @@ PackageFilter::ResultList *item = list; while (item != NULL) { // std::cerr << "Compare: "; -// t.Print(); +// t.Print(std::cerr); // std::cerr << "With table value " << i++ << ": "; -// item->Print(); +// item->Print(std::cerr); // std::cerr << std::endl; if (t.CompareAll(*item)) return item->type; @@ -199,3 +203,9 @@ } PackageFilter pkgfilter; + +#ifdef UNIT_TEST +TEST_FUNCTION TestCuPackageFilter(CuTest* tc) +{ +} +#endif Modified: software/ui/src/filter.h =================================================================== --- software/ui/src/filter.h 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/filter.h 2008-02-20 08:33:57 UTC (rev 5864) @@ -22,6 +22,7 @@ #include "taghandler.h" #include <set> +#include <iostream> #include <ept/debtags/tag.h> class PackageFilter @@ -98,16 +99,23 @@ } public: - inline void Print() { + inline void Print(std::ostream &out) const { PackageFilter::ResultList *item = list; while (item) { - std::cerr << item->name << ": "; - tagdata.Print(item); + out << item->name << ": "; + tagdata.Print(out, item); item = item->next; } } }; +inline std::ostream &operator << (std::ostream &out, const PackageFilter *filter) +{ + if (filter != NULL) + filter->Print(out); + return out; +} + extern PackageFilter pkgfilter; #endif Deleted: software/ui/src/filter_test.cpp =================================================================== --- software/ui/src/filter_test.cpp 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/filter_test.cpp 2008-02-20 08:33:57 UTC (rev 5864) @@ -1,13 +0,0 @@ -#include "filter.h" - -#include <iostream> -#include <sstream> -#include <string> - -int main(int argc, const char* argv[]) -{ - PackageFilter filter; - - filter.Print(); - return 0; -} Modified: software/ui/src/goplay.cpp =================================================================== --- software/ui/src/goplay.cpp 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/goplay.cpp 2008-02-20 08:33:57 UTC (rev 5864) @@ -329,6 +329,7 @@ } #endif +#ifndef UNIT_TEST int main(int argc, const char* argv[]) { #ifdef USE_GETTEXT @@ -504,6 +505,7 @@ } } +#endif #include <ept/debtags/debtags.tcc> Modified: software/ui/src/taghandler.cpp =================================================================== --- software/ui/src/taghandler.cpp 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/taghandler.cpp 2008-02-20 08:33:57 UTC (rev 5864) @@ -61,28 +61,28 @@ return false; } -void FilterTagHandler::PrintAll() +void FilterTagHandler::PrintAll(std::ostream &out) const { for (std::vector<Element>::const_iterator i = elements.begin(); i != elements.end(); ++i) { - std::cerr << i->name << " (" << i->position << ":" << i->flag << ")" << std::endl; + out << i->name << " (" << i->position << ":" << i->flag << ")" << std::endl; } } -void FilterTagHandler::Print(Result *result) +void FilterTagHandler::Print(std::ostream &out, Result *result) const { for (std::vector<Element>::const_iterator i = elements.begin(); i != elements.end(); ++i) { if (result->CheckAny(i->position, i->flag)) - std::cerr << i->name << " "; + out << i->name << " "; } - std::cerr << std::endl; + out << std::endl; } #ifdef UNIT_TEST -void TestCuFilterTagHandler(CuTest* tc) +TEST_FUNCTION TestCuFilterTagHandler(CuTest* tc) { FilterTagHandler tags; for (unsigned int i=0; i<70; i++) Modified: software/ui/src/taghandler.h =================================================================== --- software/ui/src/taghandler.h 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/taghandler.h 2008-02-20 08:33:57 UTC (rev 5864) @@ -99,7 +99,7 @@ return true; } - void Print() + void Print(std::ostream &out) const { unsigned int tmp_position = 0; unsigned int tmp_index = 0; @@ -108,13 +108,13 @@ unsigned int tmp_flag = 1; unsigned int tmp_data = data[tmp_index]; while (tmp_flag) { - std::cerr << ( tmp_data & tmp_flag ? "*" : "-" ) ; + out << ( tmp_data & tmp_flag ? "*" : "-" ) ; tmp_flag = tmp_flag << 1; tmp_position++; - if (tmp_position % 8 == 0) std::cerr << " " ; + if (tmp_position % 8 == 0) out << " " ; } tmp_index++; - std::cerr << " " ; + out << " " ; } } @@ -146,8 +146,8 @@ const Element *GetTag(const std::string name); void AddTag(const std::string name); bool TagExists(const std::string name); - void PrintAll(); - void Print(Result *result); + void PrintAll(std::ostream &out) const; + void Print(std::ostream &out, Result *result) const; inline void Clear() { elements.clear(); current_position=0; current_flag=1; }; Deleted: software/ui/src/taghandler_test.cpp =================================================================== --- software/ui/src/taghandler_test.cpp 2008-02-19 18:30:10 UTC (rev 5863) +++ software/ui/src/taghandler_test.cpp 2008-02-20 08:33:57 UTC (rev 5864) @@ -1,70 +0,0 @@ -#include "taghandler.h" - -#include <iostream> -#include <sstream> -#include <string> - -int main(int argc, const char* argv[]) -{ - FilterTagHandler tags; - for (unsigned int i=0; i<70; i++) - { - tags.AddTag("A"); - tags.AddTag("B"); - tags.AddTag("C"); - tags.AddTag("D"); - tags.AddTag("E"); - tags.AddTag("F"); - tags.AddTag("G"); - tags.AddTag("H"); - tags.AddTag("I"); - tags.AddTag("J"); - tags.AddTag("K"); - tags.AddTag("L"); - tags.AddTag("LL"); - tags.AddTag("M"); - tags.AddTag("N"); - tags.AddTag("O"); - tags.AddTag("P"); - tags.AddTag("Q"); - tags.AddTag("R"); - tags.AddTag("S"); - tags.AddTag("T"); - tags.AddTag("U"); - tags.AddTag("V"); - tags.AddTag("W"); - tags.AddTag("X"); - tags.AddTag("Y"); - tags.AddTag("Z"); - tags.AddTag("0"); - tags.AddTag("1"); - tags.AddTag("2"); - tags.AddTag("3"); - tags.AddTag("4"); - tags.AddTag("5"); - tags.AddTag("6"); - tags.AddTag("7"); - tags.AddTag("8"); - tags.AddTag("9"); - tags.AddTag("10"); - } - tags.PrintAll(); - - - FilterTagHandler::Result t1, t2, t3, t4, t5, t6, t7; - tags.SetTag(&t1, "A"); tags.SetTag(&t1, "7"); tags.SetTag(&t1, "MIRY"); - t1.Print(); - tags.Print(&t1); - t1.Print(); - tags.SetTag(&t2, "A"); tags.SetTag(&t2, "7"); tags.SetTag(&t2, "MIRY"); - tags.SetTag(&t3, "A"); tags.SetTag(&t3, "8"); tags.SetTag(&t3, "MIRY"); - tags.SetTag(&t4, "B"); tags.SetTag(&t4, "C"); - if (t1.CompareAny(t2)) { std::cerr << "Any: t1 == t2" << std::endl; } else { std::cerr << "Any: t1 != t2" << std::endl; } - if (t1.CompareAny(t3)) { std::cerr << "Any: t1 == t3" << std::endl; } else { std::cerr << "Any: t1 != t3" << std::endl; } - if (t1.CompareAny(t4)) { std::cerr << "Any: t1 == t4" << std::endl; } else { std::cerr << "Any: t1 != t4" << std::endl; } - if (t1.CompareAll(t2)) { std::cerr << "All: t1 == t2" << std::endl; } else { std::cerr << "All: t1 != t2" << std::endl; } - if (t1.CompareAll(t3)) { std::cerr << "All: t1 == t3" << std::endl; } else { std::cerr << "All: t1 != t3" << std::endl; } - if (t1.CompareAll(t4)) { std::cerr << "All: t1 == t4" << std::endl; } else { std::cerr << "All: t1 != t4" << std::endl; } - - return 0; -} _______________________________________________ Pkg-games-commits mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/pkg-games-commits

