158 |
send(hSocket, cmd.c_str(), cmd.length(), 0); |
send(hSocket, cmd.c_str(), cmd.length(), 0); |
159 |
} |
} |
160 |
|
|
161 |
// wait until LSCP server answers with a single line answer |
// wait until LSCP server answers with a single line answer (throws LinuxSamplerException if optional timeout exceeded) |
162 |
string LSCPTest::receiveSingleLineAnswerFromLSCPServer() { |
string LSCPTest::receiveSingleLineAnswerFromLSCPServer(uint timeout_seconds) throw (LinuxSamplerException) { |
163 |
string msg = receiveAnswerFromLSCPServer("\n"); |
string msg = receiveAnswerFromLSCPServer("\n", timeout_seconds); |
164 |
|
// remove carriage return characters |
165 |
|
string::size_type p = msg.find('\r'); |
166 |
|
for (; p != string::npos; p = msg.find(p, '\r')) msg.erase(p, 1); |
167 |
// remove the line feed at the end |
// remove the line feed at the end |
168 |
static const string linedelimiter = "\r\n"; |
static const string linedelimiter = "\n"; |
169 |
string::size_type pos = msg.rfind(linedelimiter); |
string::size_type pos = msg.rfind(linedelimiter); |
170 |
return msg.substr(0, pos); |
return msg.substr(0, pos); |
171 |
} |
} |
176 |
return __ConvertMultiLineMessage(msg); |
return __ConvertMultiLineMessage(msg); |
177 |
} |
} |
178 |
|
|
179 |
|
void LSCPTest::clearInputBuffer() { |
180 |
|
char c; |
181 |
|
while (recv(hSocket, &c, 1, 0) > 0); |
182 |
|
} |
183 |
|
|
184 |
/// wait until LSCP server answers with the given \a delimiter token at the end (throws LinuxSamplerException if optional timeout exceeded or socket error occured) |
/// wait until LSCP server answers with the given \a delimiter token at the end (throws LinuxSamplerException if optional timeout exceeded or socket error occured) |
185 |
string LSCPTest::receiveAnswerFromLSCPServer(string delimiter, uint timeout_seconds) throw (LinuxSamplerException) { |
string LSCPTest::receiveAnswerFromLSCPServer(string delimiter, uint timeout_seconds) throw (LinuxSamplerException) { |
186 |
string message; |
string message; |
249 |
} |
} |
250 |
|
|
251 |
void LSCPTest::tearDown() { |
void LSCPTest::tearDown() { |
252 |
|
clearInputBuffer(); // to avoid that the next test reads an answer from a previous test |
253 |
} |
} |
254 |
|
|
255 |
|
|
357 |
CPPUNIT_ASSERT(driver); |
CPPUNIT_ASSERT(driver); |
358 |
|
|
359 |
sendCommandToLSCPServer("CREATE AUDIO_OUTPUT_DEVICE " + *driver); |
sendCommandToLSCPServer("CREATE AUDIO_OUTPUT_DEVICE " + *driver); |
360 |
answer = receiveSingleLineAnswerFromLSCPServer(); |
answer = receiveSingleLineAnswerFromLSCPServer(120); // wait 2 minutes for an answer |
361 |
} while (answer != "OK[0]"); |
} while (answer != "OK[0]"); |
362 |
} |
} |
363 |
|
|
372 |
CPPUNIT_ASSERT(vAnswer.size() >= 4); // should at least contain tags TYPE, DESCRIPTION, FIX and MULTIPLICITY |
CPPUNIT_ASSERT(vAnswer.size() >= 4); // should at least contain tags TYPE, DESCRIPTION, FIX and MULTIPLICITY |
373 |
} |
} |
374 |
|
|
375 |
|
// Check "SET ECHO" LSCP command. |
376 |
|
void LSCPTest::test_SET_ECHO() { |
377 |
|
// enable echo mode |
378 |
|
sendCommandToLSCPServer("SET ECHO 1"); |
379 |
|
CPPUNIT_ASSERT(receiveSingleLineAnswerFromLSCPServer() == "OK"); |
380 |
|
|
381 |
|
// check if commands will actually be echoed now |
382 |
|
sendCommandToLSCPServer("GET CHANNELS"); // send an arbitrary command |
383 |
|
CPPUNIT_ASSERT(receiveSingleLineAnswerFromLSCPServer(2) == "GET CHANNELS"); |
384 |
|
receiveSingleLineAnswerFromLSCPServer(2); // throws exception if no answer received after 2s (usually we expect the answer from our command here) |
385 |
|
|
386 |
|
// disable echo mode |
387 |
|
sendCommandToLSCPServer("SET ECHO 0"); |
388 |
|
CPPUNIT_ASSERT(receiveSingleLineAnswerFromLSCPServer() == "SET ECHO 0"); // this will be echoed though |
389 |
|
CPPUNIT_ASSERT(receiveSingleLineAnswerFromLSCPServer() == "OK"); |
390 |
|
|
391 |
|
// check if commands will not be echoed now |
392 |
|
sendCommandToLSCPServer("GET CHANNELS"); |
393 |
|
CPPUNIT_ASSERT(receiveSingleLineAnswerFromLSCPServer() != "GET CHANNELS"); |
394 |
|
} |
395 |
|
|
396 |
// Check if we can shutdown the LSCP Server without problems. |
// Check if we can shutdown the LSCP Server without problems. |
397 |
void LSCPTest::testShutdownLSCPServer() { |
void LSCPTest::testShutdownLSCPServer() { |
398 |
//cout << "testShutdownLSCPServer()\n" << flush; |
//cout << "testShutdownLSCPServer()\n" << flush; |