Fix last commit
[carla.git] / source / tests.old / Engine.cpp
blob375a9e51627b99074650db1c08f3c78538f83a2b
1 /*
2 * Carla Tests
3 * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "../backend/engine/CarlaEngineInternal.hpp"
20 #include "CarlaPlugin.hpp"
22 #include "CarlaHost.h"
23 #include "CarlaUtils.hpp"
25 // -----------------------------------------------------------------------
27 CARLA_BACKEND_START_NAMESPACE
29 class CarlaEngineDummy : public CarlaEngine
31 public:
32 CarlaEngineDummy()
33 : CarlaEngine(),
34 fIsRunning(false)
38 bool init(const char* const clientName) override
40 fIsRunning = true;
41 pData->bufferSize = 512;
42 pData->sampleRate = 44100.0;
43 return CarlaEngine::init(clientName);
46 bool close() override
48 fIsRunning = false;
49 return CarlaEngine::close();
52 bool isRunning() const noexcept override
54 return fIsRunning;
57 bool isOffline() const noexcept override
59 return false;
62 EngineType getType() const noexcept override
64 return kEngineTypePlugin;
67 const char* getCurrentDriverName() const noexcept override
69 return "Dummy";
72 private:
73 bool fIsRunning;
76 CARLA_BACKEND_END_NAMESPACE
78 // -----------------------------------------------------------------------
80 CARLA_BACKEND_USE_NAMESPACE
82 #define TEST_NAME "TestName"
84 void testEngine(CarlaEngine* const eng)
86 assert(eng->getMaxClientNameSize() != 0);
87 assert(eng->getMaxPortNameSize() != 0);
88 assert(eng->getCurrentPluginCount() == 0);
89 assert(eng->getMaxPluginNumber() == 0);
90 assert(! eng->isRunning());
91 assert(eng->getPlugin(0) == nullptr);
93 const char* name1 = eng->getUniquePluginName(TEST_NAME);
94 const char* name2 = eng->getUniquePluginName(TEST_NAME);
95 const char* name3 = eng->getUniquePluginName(TEST_NAME);
97 assert(name1 != nullptr);
98 assert(name2 != nullptr);
99 assert(name3 != nullptr);
100 assert(std::strcmp(name1, TEST_NAME) == 0);
101 assert(std::strcmp(name2, TEST_NAME) == 0);
102 assert(std::strcmp(name3, TEST_NAME) == 0);
103 delete[] name1;
104 delete[] name2;
105 delete[] name3;
107 eng->init("test");
109 assert(eng->getCurrentPluginCount() == 0);
110 assert(eng->getMaxPluginNumber() != 0);
111 assert(eng->isRunning());
112 assert(eng->getPlugin(0) == nullptr);
114 name1 = eng->getUniquePluginName(TEST_NAME);
115 name2 = eng->getUniquePluginName(TEST_NAME);
116 name3 = eng->getUniquePluginName(TEST_NAME);
118 assert(name1 != nullptr);
119 assert(name2 != nullptr);
120 assert(name3 != nullptr);
121 assert(std::strcmp(name1, TEST_NAME) == 0);
122 assert(std::strcmp(name2, TEST_NAME) == 0);
123 assert(std::strcmp(name3, TEST_NAME) == 0);
124 delete[] name1;
125 delete[] name2;
126 delete[] name3;
128 eng->close();
130 // test quick init & close 3 times
131 eng->init("test1");
132 eng->close();
133 eng->init("test2");
134 eng->close();
135 eng->init("test3");
136 eng->close();
138 // leave it open
139 eng->init("test");
141 // add as much plugins as possible
142 for (;;)
144 if (! eng->addPlugin(PLUGIN_INTERNAL, nullptr, TEST_NAME, "bypass"))
145 break;
147 assert(eng->getCurrentPluginCount() != 0);
148 assert(eng->getCurrentPluginCount() == eng->getMaxPluginNumber());
149 assert(eng->getCurrentPluginCount() == MAX_DEFAULT_PLUGINS);
151 eng->close();
154 int main()
156 assert(CarlaEngine::getDriverCount() != 0);
158 #if 0
159 for (uint i=0, count=CarlaEngine::getDriverCount(); i < count && i < 4; ++i)
161 if (i == 1 || i == 2) continue;
162 carla_stdout("driver %i/%i: %s", i+1, count, CarlaEngine::getDriverName(i));
164 if (const char* const* const devNames = CarlaEngine::getDriverDeviceNames(i))
166 for (uint j=0; devNames[j] != nullptr; ++j)
168 CarlaEngine::getDriverDeviceInfo(i, devNames[j]);
172 #endif
174 assert(CarlaPlugin::getNativePluginCount() != 0);
176 for (size_t i=0, count=CarlaPlugin::getNativePluginCount(); i < count; ++i)
178 assert(CarlaPlugin::getNativePluginDescriptor(i) != nullptr);
181 CarlaEngineDummy e;
182 testEngine(&e);
184 // if (CarlaEngine* const eng = CarlaEngine::newDriverByName("PulseAudio"))
185 // {
186 // testEngine(eng);
187 // delete eng;
188 // }
190 return 0;