The code.ill.fr has been recreated and upgraded with the latest version this weekend, If you encounter any problem please inform the Helpdesk.

Commit b525fbd1 authored by legoc's avatar legoc
Browse files

(split) Added test in cmake

parent 7a7d5a79
......@@ -65,6 +65,12 @@ write_basic_package_version_file(cameoConfigVersion.cmake
VERSION ${PROJECT_VERSION}
)
#------------------------------------------------------------
# Tests
#------------------------------------------------------------
enable_testing()
add_subdirectory(tests)
#------------------------------------------------------------
# Install
......
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef CAMEO_BADFORMATEXCEPTION_H_
#define CAMEO_BADFORMATEXCEPTION_H_
#include "RemoteException.h"
namespace cameo {
class BadFormatException : public RemoteException {
public:
BadFormatException(const std::string& message);
};
}
#endif
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef CAMEO_STRINGS_H_
#define CAMEO_STRINGS_H_
#include <string>
#include <vector>
namespace cameo {
std::vector<std::string> split(const std::string& str, char c);
class Endpoint {
public:
Endpoint(const std::string& address, int port);
const std::string& getAddress() const;
int getPort() const;
static Endpoint parse(const std::string& str);
std::string toString() const;
private:
std::string m_address;
int m_port;
};
}
#endif
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "BadFormatException.h"
namespace cameo {
BadFormatException::BadFormatException(const std::string& message) :
RemoteException(message) {
}
}
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "Strings.h"
#include "BadFormatException.h"
#include <iostream>
using namespace std;
namespace cameo {
std::vector<std::string> split(const std::string& str, char c) {
vector<string> result;
int lastIndex = 0;
int index = str.find(c);
while (index != string::npos) {
result.push_back(str.substr(lastIndex, index - lastIndex));
lastIndex = index + 1;
index = str.find(c, lastIndex);
}
result.push_back(str.substr(lastIndex));
return result;
}
Endpoint::Endpoint(const std::string& address, int port) {
m_address = address;
m_port = port;
}
const std::string& Endpoint::getAddress() const {
return m_address;
}
int Endpoint::getPort() const {
return m_port;
}
Endpoint Endpoint::parse(const std::string& str) {
if (str.substr(0, 6) != "tcp://") {
throw new BadFormatException("Bad format for endpoint " + str);
}
string substr = str.substr(7);
vector<string> tokens = split(substr, ':');
if (tokens.size() != 2) {
throw new BadFormatException("Bad format for endpoint " + str);
}
string address = tokens[0];
int port = 0;
try {
port = stoi(tokens[1]);
}
catch (...) {
throw new BadFormatException("Bad format for endpoint " + str);
}
return Endpoint(address, port);
}
std::string Endpoint::toString() const {
return string("tcp://") + m_address + ":" + to_string(m_port);
}
}
add_executable(teststrings TestStrings.cpp)
target_link_libraries(teststrings PUBLIC
cameo
)
add_test(cameo teststrings)
\ No newline at end of file
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef CAMEO_TEST_H_
#define CAMEO_TEST_H_
#define ALEPH_ASSERT_THROW( condition ) \
{ \
if( !( condition ) ) \
{ \
throw std::runtime_error( std::string( __FILE__ ) \
+ std::string( ":" ) \
+ std::to_string( __LINE__ ) \
+ std::string( " in " ) \
+ std::string( __PRETTY_FUNCTION__ ) \
); \
} \
}
#define ALEPH_ASSERT_EQUAL( x, y ) \
{ \
if( ( x ) != ( y ) ) \
{ \
throw std::runtime_error( std::string( __FILE__ ) \
+ std::string( ":" ) \
+ std::to_string( __LINE__ ) \
+ std::string( " in " ) \
+ std::string( __PRETTY_FUNCTION__ ) \
+ std::string( ": " ) \
+ std::to_string( ( x ) ) \
+ std::string( " != " ) \
+ std::to_string( ( y ) ) \
); \
} \
}
#endif
#include "Test.h"
#include "../include/Strings.h"
#include <iostream>
using namespace std;
using namespace cameo;
int main(int argc, char *argv[]) {
Endpoint endpoint("gamma75", 9999);
cout << endpoint.toString() << endl;
ALEPH_ASSERT_EQUAL(1, 1);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment