@@ -56,6 +56,10 @@ carla-discovery-native | |||||
carla-discovery-posix32 | carla-discovery-posix32 | ||||
carla-discovery-posix64 | carla-discovery-posix64 | ||||
source/tests/CarlaString | |||||
source/tests/RtList | |||||
source/tests/Thread | |||||
# Docs | # Docs | ||||
doc/carla-backend/ | doc/carla-backend/ | ||||
doc/carla-bridge/ | doc/carla-bridge/ | ||||
@@ -0,0 +1,173 @@ | |||||
/* | |||||
* Carla Tests | |||||
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU General Public License as | |||||
* published by the Free Software Foundation; either version 2 of | |||||
* the License, or any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* For a full copy of the GNU General Public License see the GPL.txt file | |||||
*/ | |||||
#include "carla_utils.hpp" | |||||
#include <cassert> | |||||
int main() | |||||
{ | |||||
CarlaString str; | |||||
// empty | |||||
assert(str.length() == 0); | |||||
assert(str.length() == std::strlen("")); | |||||
assert(str.isEmpty()); | |||||
assert(str.contains("")); | |||||
assert(! str.isNotEmpty()); | |||||
assert(! str.contains("-")); | |||||
assert(! str.isDigit(0)); | |||||
// single number | |||||
str = "5"; | |||||
assert(str.length() == 1); | |||||
assert(str.length() == std::strlen("5")); | |||||
assert(str.isNotEmpty()); | |||||
assert(str.contains("")); | |||||
assert(str.contains("5")); | |||||
assert(str.isDigit(0)); | |||||
assert(! str.isEmpty()); | |||||
assert(! str.contains("6")); | |||||
assert(! str.isDigit(1)); | |||||
// single number, using constructor | |||||
str = CarlaString(5); | |||||
assert(str.length() == 1); | |||||
assert(str.length() == std::strlen("5")); | |||||
assert(str.isNotEmpty()); | |||||
assert(str.contains("")); | |||||
assert(str.contains("5")); | |||||
assert(str.isDigit(0)); | |||||
assert(! str.isEmpty()); | |||||
assert(! str.contains("6")); | |||||
assert(! str.isDigit(1)); | |||||
// decimal number | |||||
str = CarlaString(51); | |||||
assert(str.length() == 2); | |||||
assert(str.length() == std::strlen("51")); | |||||
assert(str.isNotEmpty()); | |||||
assert(str.contains("")); | |||||
assert(str.contains("1")); | |||||
assert(str.contains("51")); | |||||
assert(str.isDigit(0)); | |||||
assert(str.isDigit(1)); | |||||
assert(! str.isEmpty()); | |||||
assert(! str.contains("6")); | |||||
assert(! str.isDigit(2)); | |||||
assert(! str.isDigit(-1)); | |||||
// negative number | |||||
str = CarlaString(-51); | |||||
assert(str.length() == 3); | |||||
assert(str.length() == std::strlen("-51")); | |||||
assert(str.isNotEmpty()); | |||||
assert(str.contains("")); | |||||
assert(str.contains("-5")); | |||||
assert(str.contains("51")); | |||||
assert(str.isDigit(1)); | |||||
assert(str.isDigit(2)); | |||||
assert(! str.isEmpty()); | |||||
assert(! str.contains("6")); | |||||
assert(! str.isDigit(0)); | |||||
assert(! str.isDigit(-1)); | |||||
// small operations | |||||
str += "ah"; | |||||
assert(str.length() == 5); | |||||
assert(str.length() == std::strlen("-51ah")); | |||||
assert(str.contains("-51ah")); | |||||
assert(! str.isDigit(3)); | |||||
// hexacimal number | |||||
unsigned int n = 0x91; | |||||
str += CarlaString(n, true); | |||||
assert(str.length() == 9); | |||||
assert(str.length() == std::strlen("-51ah0x91")); | |||||
assert(str.contains("-51ah0x91")); | |||||
assert(! str.isDigit(6)); | |||||
// float number | |||||
str += CarlaString(0.0102f); | |||||
assert(str.length() == 17); | |||||
assert(str.length() == std::strlen("-51ah0x910.010200")); | |||||
assert(str.contains("-51ah0x91")); | |||||
assert(! str.isDigit(6)); | |||||
// double number | |||||
str += CarlaString(7.9642); | |||||
assert(str.length() == 23); | |||||
assert(str.length() == std::strlen("-51ah0x910.0102007.9642")); | |||||
assert(str.contains("7.9642")); | |||||
// replace | |||||
str.replace('0', 'k'); | |||||
str.replace('k', 'O'); | |||||
str.replace('O', '0'); | |||||
str.replace('0', '\0'); // shouldn't do anything | |||||
// truncate | |||||
str.truncate(11); | |||||
assert(str.length() == 11); | |||||
assert(str.length() == std::strlen("-51ah0x910.")); | |||||
// basic | |||||
str.toBasic(); | |||||
assert(str.length() == 11); | |||||
assert(str == "_51ah0x910_"); | |||||
// upper | |||||
str.toUpper(); | |||||
assert(str.length() == 11); | |||||
assert(str == "_51AH0X910_"); | |||||
// lower | |||||
str.toLower(); | |||||
assert(str.length() == 11); | |||||
assert(str == "_51ah0x910_"); | |||||
// random stuff | |||||
CarlaString str1(1.23); | |||||
str1 += "_ ?"; | |||||
CarlaString str2("test1"); | |||||
str2 = "test2"; | |||||
str2 += ".0"; | |||||
CarlaString str3("1.23_ ?test2.0 final"); | |||||
CarlaString str4 = "" + str1 + str2 + " final"; | |||||
assert(str3 == "1.23_ ?test2.0 final"); | |||||
assert(str3 == str4); | |||||
assert(str3.length() == str4.length()); | |||||
assert(str3.length() == std::strlen("1.23_ ?test2.0 final")); | |||||
CarlaString str5 = "ola " + str + " " + CarlaString(6); | |||||
assert(str5 == "ola _51ah0x910_ 6"); | |||||
assert(str5.length() == std::strlen("ola _51ah0x910_ 6")); | |||||
printf("FINAL: \"%s\"\n", (const char*)str5); | |||||
// clear | |||||
str.clear(); | |||||
assert(str.length() == 0); | |||||
assert(str.length() == std::strlen("")); | |||||
assert(str == ""); | |||||
return 0; | |||||
} |
@@ -0,0 +1,39 @@ | |||||
#!/usr/bin/make -f | |||||
# Makefile for carla tests # | |||||
# ------------------------ # | |||||
# Created by falkTX | |||||
# | |||||
include ../Makefile.mk | |||||
# -------------------------------------------------------------- | |||||
BUILD_CXX_FLAGS += -I../backend -I../includes -I../utils | |||||
BUILD_CXX_FLAGS += $(shell pkg-config --cflags QtCore) | |||||
LINK_FLAGS += $(shell pkg-config --libs QtCore) | |||||
TARGETS = CarlaString RtList Thread | |||||
all: $(TARGETS) RUN | |||||
# -------------------------------------------------------------- | |||||
CarlaString: CarlaString.cpp | |||||
$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||||
RtList: RtList.cpp ../libs/rtmempool.a | |||||
$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -o $@ | |||||
Thread_: Thread.cpp | |||||
$(CXX) $^ $(BUILD_CXX_FLAGS) $(LINK_FLAGS) -pthread -lpthread -o $@ | |||||
RUN: $(TARGETS) | |||||
./CarlaString && ./RtList && ./Thread | |||||
# -------------------------------------------------------------- | |||||
clean: | |||||
rm -f $(TARGETS) | |||||
debug: | |||||
$(MAKE) DEBUG=true |
@@ -0,0 +1,158 @@ | |||||
/* | |||||
* Carla Tests | |||||
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU General Public License as | |||||
* published by the Free Software Foundation; either version 2 of | |||||
* the License, or any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* For a full copy of the GNU General Public License see the GPL.txt file | |||||
*/ | |||||
#include "carla_utils.hpp" | |||||
#include "rt_list.hpp" | |||||
#include <cassert> | |||||
const unsigned short MIN_RT_EVENTS = 152; | |||||
const unsigned short MAX_RT_EVENTS = 512; | |||||
struct MyData { | |||||
CarlaString str; | |||||
int idStr; | |||||
MyData() | |||||
: idStr(-1) {} | |||||
MyData(int id) | |||||
: str(id), | |||||
idStr(id) {} | |||||
MyData(MyData&) = delete; | |||||
MyData(const MyData&) = delete; | |||||
}; | |||||
struct PostRtEvents { | |||||
CarlaMutex mutex; | |||||
RtList<MyData>::Pool dataPool; | |||||
RtList<MyData> data; | |||||
RtList<MyData> dataPendingRT; | |||||
PostRtEvents() | |||||
: dataPool(MIN_RT_EVENTS, MAX_RT_EVENTS), | |||||
data(&dataPool), | |||||
dataPendingRT(&dataPool) {} | |||||
~PostRtEvents() | |||||
{ | |||||
clear(); | |||||
} | |||||
void appendRT(const MyData& event) | |||||
{ | |||||
dataPendingRT.append(event); | |||||
} | |||||
void clear() | |||||
{ | |||||
mutex.lock(); | |||||
data.clear(); | |||||
dataPendingRT.clear(); | |||||
mutex.unlock(); | |||||
} | |||||
void trySplice() | |||||
{ | |||||
if (mutex.tryLock()) | |||||
{ | |||||
dataPendingRT.splice(data, true); | |||||
mutex.unlock(); | |||||
} | |||||
} | |||||
//void appendNonRT(const PluginPostRtEvent& event) | |||||
//{ | |||||
// data.append_sleepy(event); | |||||
//} | |||||
} postRtEvents; | |||||
void run4Tests() | |||||
{ | |||||
unsigned short k = 0; | |||||
MyData allMyData[MAX_RT_EVENTS]; | |||||
// Make a safe copy of events while clearing them | |||||
postRtEvents.mutex.lock(); | |||||
while (! postRtEvents.data.isEmpty()) | |||||
{ | |||||
MyData& my = postRtEvents.data.getFirst(true); | |||||
allMyData[k++] = my; | |||||
//std::memcpy(&allMyData[i++], &my, sizeof(MyData)); | |||||
} | |||||
postRtEvents.mutex.unlock(); | |||||
printf("Post-Rt Event Count: %i\n", k); | |||||
assert(k == 4); | |||||
// data should be empty now | |||||
assert(postRtEvents.data.count() == 0); | |||||
assert(postRtEvents.data.isEmpty()); | |||||
assert(postRtEvents.dataPendingRT.count() == 0); | |||||
assert(postRtEvents.dataPendingRT.isEmpty()); | |||||
// Handle events now | |||||
for (unsigned short i=0; i < k; i++) | |||||
{ | |||||
const MyData& my = allMyData[i]; | |||||
printf("Got data: %i %s\n", my.idStr, (const char*)my.str); | |||||
} | |||||
} | |||||
int main() | |||||
{ | |||||
MyData m1(1); | |||||
MyData m2(2); | |||||
MyData m3(3); | |||||
MyData m4(4); | |||||
// start | |||||
assert(postRtEvents.data.count() == 0); | |||||
assert(postRtEvents.data.isEmpty()); | |||||
assert(postRtEvents.dataPendingRT.count() == 0); | |||||
assert(postRtEvents.dataPendingRT.isEmpty()); | |||||
// single append | |||||
postRtEvents.appendRT(m1); | |||||
postRtEvents.trySplice(); | |||||
assert(postRtEvents.data.count() == 1); | |||||
assert(postRtEvents.dataPendingRT.count() == 0); | |||||
// +3 appends | |||||
postRtEvents.appendRT(m2); | |||||
postRtEvents.appendRT(m4); | |||||
postRtEvents.appendRT(m3); | |||||
postRtEvents.trySplice(); | |||||
assert(postRtEvents.data.count() == 4); | |||||
assert(postRtEvents.dataPendingRT.count() == 0); | |||||
run4Tests(); | |||||
// reset | |||||
postRtEvents.clear(); | |||||
assert(postRtEvents.data.count() == 0); | |||||
assert(postRtEvents.data.isEmpty()); | |||||
assert(postRtEvents.dataPendingRT.count() == 0); | |||||
assert(postRtEvents.dataPendingRT.isEmpty()); | |||||
return 0; | |||||
} |
@@ -0,0 +1,92 @@ | |||||
/* | |||||
* Carla Tests | |||||
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the GNU General Public License as | |||||
* published by the Free Software Foundation; either version 2 of | |||||
* the License, or any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* For a full copy of the GNU General Public License see the GPL.txt file | |||||
*/ | |||||
#include "carla_utils.hpp" | |||||
#include <cassert> | |||||
class MyThread : public CarlaThread | |||||
{ | |||||
public: | |||||
MyThread(bool wait) | |||||
: blockWait(wait) | |||||
{ | |||||
} | |||||
protected: | |||||
void run() | |||||
{ | |||||
printf("RUN(%i)\n", blockWait); | |||||
if (blockWait) | |||||
{ | |||||
for (int i=0; i < 100; i++) | |||||
{ | |||||
carla_msleep(50); | |||||
printf("RUN(%i) - BLOCKING\n", blockWait); | |||||
} | |||||
} | |||||
printf("RUN(%i) - FINISHED\n", blockWait); | |||||
} | |||||
private: | |||||
bool blockWait; | |||||
}; | |||||
int main() | |||||
{ | |||||
MyThread t1(false); | |||||
MyThread t2(true); | |||||
MyThread t3(true); | |||||
MyThread t4(true); | |||||
MyThread t5(false); | |||||
t1.start(); | |||||
t2.start(); | |||||
//t3.start(); | |||||
//t3.waitForStarted(); | |||||
//t3.stop(); | |||||
t1.waitForStarted(); | |||||
t2.waitForStarted(); | |||||
printf("THREADS STARTED\n"); | |||||
// test if threds keep working | |||||
carla_sleep(1); | |||||
printf("THREAD1 STOPPING...\n"); | |||||
if (t1.isRunning() && ! t1.stop(500)) | |||||
{ | |||||
printf("THREAD1 FAILED, TERMINATE\n"); | |||||
t1.terminate(); | |||||
} | |||||
printf("THREAD2 STOPPING...\n"); | |||||
if (t2.isRunning() && ! t2.stop(500)) | |||||
{ | |||||
printf("THREAD2 FAILED, TERMINATE\n"); | |||||
t2.terminate(); | |||||
} | |||||
return 0; | |||||
} |