From cafd11c80a52835c2917c11cdb57d4645fba5bdb Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 3 Jul 2014 03:31:00 +0100 Subject: [PATCH] More tests --- .gitignore | 3 +- source/tests/CarlaString.cpp | 2 +- .../tests/{Exception.cpp => Exceptions.cpp} | 41 ++++++++++++------- source/tests/Makefile | 33 +++++++-------- source/tests/Print.cpp | 8 +++- source/tests/RtLinkedList.cpp | 10 ++--- source/utils/CarlaLibCounter.hpp | 3 +- 7 files changed, 55 insertions(+), 45 deletions(-) rename source/tests/{Exception.cpp => Exceptions.cpp} (60%) diff --git a/.gitignore b/.gitignore index 996787d78..2a3fa246d 100644 --- a/.gitignore +++ b/.gitignore @@ -83,11 +83,12 @@ source/frontend/Makefile source/tests/ansi-pedantic-test_* source/tests/CarlaString source/tests/CarlaUtils +source/tests/Exceptions +source/tests/Print source/tests/RDF source/tests/EngineEvents source/tests/PipeServer -source/tests/Print source/tests/RtLinkedList source/tests/RtLinkedListGnu diff --git a/source/tests/CarlaString.cpp b/source/tests/CarlaString.cpp index 2c3c28eca..878226e73 100644 --- a/source/tests/CarlaString.cpp +++ b/source/tests/CarlaString.cpp @@ -237,7 +237,7 @@ int main() assert(str5.rfind("haha!", &found) == str5.length()); assert(! found); - printf("FINAL: \"%s\"\n", str5.buffer()); + carla_stdout("FINAL: \"%s\"", str5.buffer()); // clear str.clear(); diff --git a/source/tests/Exception.cpp b/source/tests/Exceptions.cpp similarity index 60% rename from source/tests/Exception.cpp rename to source/tests/Exceptions.cpp index 5ecec40af..773928797 100644 --- a/source/tests/Exception.cpp +++ b/source/tests/Exceptions.cpp @@ -1,5 +1,5 @@ /* - * Carla Tests + * Carla Exception Tests * Copyright (C) 2013-2014 Filipe Coelho * * This program is free software; you can redistribute it and/or @@ -18,6 +18,8 @@ #include "CarlaDefines.h" #include "CarlaUtils.hpp" +// ----------------------------------------------------------------------- + struct Struct1 { Struct1() noexcept {} ~Struct1() noexcept {} @@ -31,33 +33,42 @@ struct Struct1 { struct Struct2 { Struct2() { throw 2; } ~Struct2() noexcept {} - - void throwHere() - { - throw 3; - } }; +// ----------------------------------------------------------------------- + int main() { carla_safe_assert("test here", __FILE__, __LINE__); Struct1 a; - Struct2* b = nullptr; + Struct1* b; + Struct2* c = nullptr; try { a.throwHere(); - } CARLA_SAFE_EXCEPTION("Struct1 throw", carla_stdout("after text1 here");) + } CARLA_SAFE_EXCEPTION("Struct1 a throw"); try { - b = new Struct2; - } CARLA_SAFE_EXCEPTION("Struct2 throw", carla_stdout("after text2 here");) + b = new Struct1; + } CARLA_SAFE_EXCEPTION("Struct1 b throw constructor"); - if (b != nullptr) - { - delete b; - b = nullptr; - } + assert(b != nullptr); + + try { + b->throwHere(); + } CARLA_SAFE_EXCEPTION("Struct1 b throw runtime"); + + delete b; + b = nullptr; + + try { + c = new Struct2; + } CARLA_SAFE_EXCEPTION("Struct2 c throw"); + + assert(c == nullptr); return 0; } + +// ----------------------------------------------------------------------- diff --git a/source/tests/Makefile b/source/tests/Makefile index 1ce6254ee..92d4a38f7 100644 --- a/source/tests/Makefile +++ b/source/tests/Makefile @@ -40,10 +40,10 @@ endif # -------------------------------------------------------------- TARGETS = ansi-pedantic-test_c ansi-pedantic-test_c99 -TARGETS += CarlaString CarlaUtils RDF +TARGETS += CarlaString CarlaUtils Exceptions Print RDF # ansi-pedantic-test_cxx ansi-pedantic-test_cxx11 -# TARGETS += EngineEvents PipeServer Print RtLinkedList RtLinkedListGnu Utils +# TARGETS += EngineEvents PipeServer RtLinkedList RtLinkedListGnu all: $(TARGETS) @@ -73,6 +73,14 @@ CarlaUtils: CarlaUtils.cpp ../utils/*.hpp $(shell pkg-config --cflags --libs QtCore) -isystem /usr/include/qt4 valgrind --leak-check=full ./$@ +Exceptions: Exceptions.cpp + $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ + valgrind --leak-check=full ./$@ + +Print: Print.cpp ../utils/CarlaUtils.hpp + $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ + valgrind --leak-check=full ./$@ + RDF: RDF.cpp ../modules/ladspa_rdf.hpp ../modules/lv2_rdf.hpp $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ valgrind --leak-check=full ./$@ @@ -81,7 +89,7 @@ RDF: RDF.cpp ../modules/ladspa_rdf.hpp ../modules/lv2_rdf.hpp ChildProcess: ChildProcess.cpp $(CXX) $< $(PEDANTIC_CXX_FLAGS) ../modules/juce_core.a -ldl -lpthread -lrt -o $@ -# valgrind --leak-check=full ./$@ + valgrind --leak-check=full ./$@ CarlaMutex: CarlaMutex.cpp ../utils/CarlaMutex.hpp $(CXX) $< -lpthread -o $@ @@ -98,29 +106,21 @@ Engine: Engine.cpp env LD_LIBRARY_PATH=../backend valgrind --leak-check=full ./$@ # ../modules/juce_audio_basics.a ../modules/juce_core.a \ -Exception: Exception.cpp - $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ -# valgrind ./$@ - EngineEvents: EngineEvents.cpp $(CXX) $< $(PEDANTIC_CXX_FLAGS) -L../backend -lcarla_standalone2 -o $@ env LD_LIBRARY_PATH=../backend valgrind ./$@ PipeServer: PipeServer.cpp ../utils/CarlaPipeUtils.hpp $(CXX) $< $(PEDANTIC_CXX_FLAGS) -lpthread -o $@ -# valgrind ./$@ - -Print: Print.cpp ../utils/CarlaUtils.hpp - $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ - valgrind ./$@ + valgrind --leak-check=full ./$@ RtLinkedList: RtLinkedList.cpp ../utils/LinkedList.hpp ../utils/RtLinkedList.hpp ../modules/rtmempool.a $(CXX) $< ../modules/rtmempool.a $(PEDANTIC_CXX_FLAGS) -lpthread -o $@ - valgrind ./$@ + valgrind --leak-check=full ./$@ RtLinkedListGnu: RtLinkedList.cpp ../utils/LinkedList.hpp ../utils/RtLinkedList.hpp ../modules/rtmempool.a $(CXX) $< ../modules/rtmempool.a $(GNU_CXX_FLAGS) -lpthread -o $@ - valgrind ./$@ + valgrind --leak-check=full ./$@ # -------------------------------------------------------------- @@ -132,11 +132,6 @@ Rewire.cpp.o: Rewire.cpp # -------------------------------------------------------------- -../modules/%.a: - $(MAKE) -C ../modules $* - -# -------------------------------------------------------------- - clean: rm -f *.o $(TARGETS) diff --git a/source/tests/Print.cpp b/source/tests/Print.cpp index d5b6fd1df..17c18f53c 100644 --- a/source/tests/Print.cpp +++ b/source/tests/Print.cpp @@ -1,6 +1,6 @@ /* - * Carla Tests - * Copyright (C) 2013 Filipe Coelho + * Carla Print Tests + * Copyright (C) 2013-2014 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -17,6 +17,8 @@ #include "CarlaUtils.hpp" +// ----------------------------------------------------------------------- + int main() { carla_debug("DEBUG"); @@ -25,3 +27,5 @@ int main() carla_stderr2("STDERR2"); return 0; } + +// ----------------------------------------------------------------------- diff --git a/source/tests/RtLinkedList.cpp b/source/tests/RtLinkedList.cpp index aa954d630..56db5ee70 100644 --- a/source/tests/RtLinkedList.cpp +++ b/source/tests/RtLinkedList.cpp @@ -1,6 +1,6 @@ /* * Carla Tests - * Copyright (C) 2013 Filipe Coelho + * Copyright (C) 2013-2014 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -68,7 +68,7 @@ struct PostRtEvents { { if (mutex.tryLock()) { - dataPendingRT.spliceAppend(data); + dataPendingRT.spliceAppendTo(data); mutex.unlock(); } } @@ -91,7 +91,7 @@ void run5Tests() postRtEvents.mutex.unlock(); - printf("Post-Rt Event Count: %i\n", k); + carla_stdout("Post-Rt Event Count: %i", k); assert(k == 5); // data should be empty now @@ -105,7 +105,7 @@ void run5Tests() { const MyData& my(allMyData[i]); - printf("Got data: %i %s\n", my.id, my.str.buffer()); + carla_stdout("Got data: %i %s", my.id, my.str.buffer()); } } @@ -143,7 +143,7 @@ int main() { const MyData& my(it.getValue()); - printf("FOR DATA!!!: %i %s\n", my.id, my.str.buffer()); + carla_stdout("FOR DATA!!!: %i %s", my.id, my.str.buffer()); if (my.id == 1) { diff --git a/source/utils/CarlaLibCounter.hpp b/source/utils/CarlaLibCounter.hpp index 50721d500..49c27fa70 100644 --- a/source/utils/CarlaLibCounter.hpp +++ b/source/utils/CarlaLibCounter.hpp @@ -65,8 +65,7 @@ public: try { dfilename = carla_strdup(filename); - } - CARLA_SAFE_EXCEPTION_RETURN("LibCounter::open", nullptr); + } CARLA_SAFE_EXCEPTION_RETURN("LibCounter::open", nullptr); const CarlaMutexLocker cml(fMutex);