1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
* Copyright 2009- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/
#include <iostream>
#include <stdexcept>
#include <boost/test/unit_test.hpp>
#include "ecflow/node/InLimit.hpp"
#include "ecflow/node/Task.hpp"
#include "ecflow/test/scaffold/Naming.hpp"
#include "ecflow/test/scaffold/Serialisation.hpp"
using namespace std;
using namespace ecf;
BOOST_AUTO_TEST_SUITE(U_Node)
BOOST_AUTO_TEST_SUITE(T_InLimit)
BOOST_AUTO_TEST_CASE(test_inlimit_basics) {
ECF_NAME_THIS_TEST();
{
InLimit empty;
InLimit empty2;
BOOST_CHECK_MESSAGE(empty == empty2, "Equality failed");
InLimit l1("name", "path");
InLimit l2("name", "path");
BOOST_CHECK_MESSAGE(l1 == l2, "Equality failed");
InLimit a("name", "path", 10);
InLimit b("name", "path");
BOOST_CHECK_MESSAGE(!(a == b), "Equality passed when should fail");
}
{
InLimit inlim("fred", "/path/to/node", 1, true);
{
InLimit testCopy = inlim;
BOOST_CHECK_MESSAGE(testCopy == inlim, "Copy constructor failed");
}
{
InLimit testCopy;
testCopy = inlim;
BOOST_CHECK_MESSAGE(testCopy == inlim, "Assignment failed");
}
}
{
InLimit inlim("fred", "/path/to/node", 1, false);
{
InLimit testCopy = inlim;
BOOST_CHECK_MESSAGE(testCopy == inlim, "Copy constructor failed");
}
{
InLimit testCopy;
testCopy = inlim;
BOOST_CHECK_MESSAGE(testCopy == inlim, "Assignment failed");
}
}
{
InLimit inlim("fred", "/path/to/node", 1, false, true);
{
InLimit testCopy = inlim;
BOOST_CHECK_MESSAGE(testCopy == inlim, "Copy constructor failed");
}
{
InLimit testCopy;
testCopy = inlim;
BOOST_CHECK_MESSAGE(testCopy == inlim, "Assignment failed");
}
}
}
BOOST_AUTO_TEST_CASE(test_inlimit_duplicates) {
ECF_NAME_THIS_TEST();
InLimit inlim("fred", "/path/to/node", 1, true);
task_ptr task = Task::create("task");
task->addInLimit(inlim);
// duplicate should throw
BOOST_REQUIRE_THROW(task->addInLimit(inlim), std::runtime_error);
// still a duplicate
InLimit inlim2("fred", "/path/to/node");
BOOST_REQUIRE_THROW(task->addInLimit(inlim2), std::runtime_error);
}
// Globals used throughout the test
static std::string fileName = "test_InLimit_serialisation.txt";
BOOST_AUTO_TEST_CASE(test_InLimit_serialisation) {
ECF_NAME_THIS_TEST();
{
// save and restore the default constructor
doSaveAndRestore<InLimit>(fileName);
InLimit saved("limitName", "/path/to/some/node", 20, true);
save(fileName, saved);
InLimit restored;
restore(fileName, restored);
BOOST_CHECK_MESSAGE(saved == restored, " save and restored don't match");
std::remove(fileName.c_str());
}
{
InLimit saved("limitName", "/path/to/some/node", 20, false, true);
save(fileName, saved);
InLimit restored;
restore(fileName, restored);
BOOST_CHECK_MESSAGE(saved == restored, " save and restored don't match");
std::remove(fileName.c_str());
}
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|