/[svn]/linuxsampler/trunk/src/testcases/LSCPTest.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/testcases/LSCPTest.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 223 by schoenebeck, Sun Aug 15 20:18:55 2004 UTC revision 224 by schoenebeck, Sat Aug 21 15:31:36 2004 UTC
# Line 158  void LSCPTest::sendCommandToLSCPServer(s Line 158  void LSCPTest::sendCommandToLSCPServer(s
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  }  }
# Line 173  vector<string> LSCPTest::receiveMultiLin Line 176  vector<string> LSCPTest::receiveMultiLin
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;
# Line 241  void LSCPTest::setUp() { Line 249  void LSCPTest::setUp() {
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    
# Line 348  void LSCPTest::test_GET_AUDIO_OUTPUT_CHA Line 357  void LSCPTest::test_GET_AUDIO_OUTPUT_CHA
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    
# Line 363  void LSCPTest::test_GET_AUDIO_OUTPUT_CHA Line 372  void LSCPTest::test_GET_AUDIO_OUTPUT_CHA
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;

Legend:
Removed from v.223  
changed lines
  Added in v.224

  ViewVC Help
Powered by ViewVC