void checkUpdate(int b, int N, int64 size, bool verbose = false) { if(verbose) cout << " Testing updates b = "<< b << " N = " << N << " size = " << size << endl; OlaBuffer< float > ob(b,N); cout << " beta (number of levels) = " << ob.levels(size) << endl; for(int64 k = 0 ; k < size ; ++k) { if(verbose) cout << " =======================" << endl; if(verbose) cout << " testing update of delta at k = " << k << " N = " << N << " size = " << size << endl; vector<float> data(size,0); data[k] = 1;// ** if(verbose) cout << "k = " << k << endl; counted_ptr<vector<float> > buffer = ob.computeBuffer(data); ob.updateBuffer(*buffer,k,-1); for(int i = (int) buffer->size() -1 ; i >= 0 ; --i) { if(abs((*buffer)[i]) > 0.00001) { cout << " buffer should have gone to zero " << endl; for (int l = 0; l < (int) buffer->size() ; ++l) cout << (*buffer)[l] << " "; cout << endl; throw TestFailedException((*buffer)[i]); } } counted_ptr<vector<float> > newbuffer = ob.computeBuffer(data); ob.updateBuffer(*buffer,k,1.0f); for(int i = 0; i < (int) buffer->size(); ++i) { if(abs((*buffer)[i] - (*newbuffer)[i]) > 0.00001) { cout << " updating should be the same as tranforming " << endl; for (int l = 0; l < (int) buffer->size() ; ++l) cout << (*buffer)[l] << " "; cout << endl; for (int l = 0; l < (int) newbuffer->size() ; ++l) cout << (*newbuffer)[l] << " "; cout << endl; throw TestFailedException((*buffer)[i] - (*newbuffer)[i]); } } } if(verbose) cout << " *Test succesful* " << endl; }
void run() { const char* testData = "Twenty-five or six to four"; const size_t testDataLen = strlen(testData); char* buff = reinterpret_cast<char*>(calloc(testDataLen + 1, 1)); const int port = 1337; try { // Create a listener and a client connection TCPListener server(port); TCPConnection client; // Start the server and connect to it server.start(); client.connect(IPEndPoint(IP(127, 0, 0, 1), port)); // Accept the connection auto serverConn = server.accept(); // Test sending from the server to the client serverConn->send(testData, testDataLen); client.receive(buff, testDataLen); if (strcmp(testData, buff) != 0) throw TestFailedException("Data sent from server to client didn't go through properly"); // Reset the buffer and try sending from // the client to the server memset(buff, 0, testDataLen); serverConn->shutDownSending(); client.shutDownReceiving(); client.send(testData, testDataLen); serverConn->receive(buff, testDataLen); if (strcmp(testData, buff) != 0) throw TestFailedException("Data sent from client to server didn't go through properly"); // Shut down the connections client.disconnect(); if (serverConn->receive(buff, testDataLen) != 0) throw TestFailedException("The server was not notified when the client disconnected"); serverConn->disconnect(); free(buff); } catch (...) { free(buff); throw; } }
void TestsListener::testHasFailed(const String & msg) { setTestExecutionComment(msg); errorsLog(msg); throw TestFailedException(); }
void run() { // Test IP construction IP fromString("192.168.0.1"); if (fromString.getOctet(0) != 192 || fromString.getOctet(1) != 168 || fromString.getOctet(2) != 0 || fromString.getOctet(3) != 1) throw TestFailedException("An IP could not be properly constructed from a string."); // Test provided octet construction IP fromOctets(192, 168, 0, 1); if (fromOctets.getOctet(0) != 192 || fromOctets.getOctet(1) != 168 || fromOctets.getOctet(2) != 0 || fromOctets.getOctet(3) != 1) throw TestFailedException("An IP could not be properly constructed from octets."); // Test string representation if (strcmp("192.168.0.1", fromOctets.getAsString().c_str()) != 0) throw TestFailedException("An IP's string representation was incorrect."); // Test inequality if (fromString != fromOctets) throw TestFailedException("Inequality operator failed"); // Test equality IP different = (std::string) "127.0.0.1"; if (different.getOctet(0) != 127 || different.getOctet(1) != 0 || different.getOctet(2) != 0 || different.getOctet(3) != 1) throw TestFailedException("An IP could not be constructed from a string."); if (fromOctets == different) throw TestFailedException("Equality operator failed"); // Test assignment from string different = "74.125.113.99"; if (different.getOctet(0) != 74 || different.getOctet(1) != 125 || different.getOctet(2) != 113 || different.getOctet(3) != 99) throw TestFailedException("An IP could not be assigned from a string."); // Test binary representation unsigned int binRep = (208 << 24) + (47 << 16) + (17 << 8) + 18; IP fromBin(binRep, IP::BO_HOST); if (binRep != fromBin.getAsBinary(IP::BO_HOST)) throw TestFailedException("An IP's binary representation was incorrect."); }
std::string TestBase::getTestTempDirectory() { if (!m_test_dir.empty()) return m_test_dir; char buf[32]; snprintf(buf, sizeof(buf), "%08X", myrand()); m_test_dir = fs::TempPath() + DIR_DELIM "mttest_" + buf; if (!fs::CreateDir(m_test_dir)) throw TestFailedException(); return m_test_dir; }
void TestsListener::testHasFailed() { std::cout << "F"; theInstance()._failed++; throw TestFailedException(); }