From 0e426ff6dfb960c105908a437c435924e59eb822 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Thu, 16 Oct 2014 00:39:35 +0000 Subject: reorganized code git-svn-id: file:///var/local/svn/basicwriter@58 daaaf23c-2e50-4459-9457-1e69db5a47bf --- CMakeLists.txt | 56 ++--------- build.sh | 4 + clean.sh | 5 + dependencies.txt | 4 +- src/main.cpp | 41 -------- test/core/model/RangeSet.cpp | 222 +++++++++++++++++++++++++++++++++++++++++++ test/model/GraphNode.cpp | 51 ---------- test/model/RangeSet.cpp | 222 ------------------------------------------- test/model/domain/Layer.cpp | 48 ---------- 9 files changed, 243 insertions(+), 410 deletions(-) create mode 100755 build.sh create mode 100755 clean.sh delete mode 100644 src/main.cpp create mode 100644 test/core/model/RangeSet.cpp delete mode 100644 test/model/GraphNode.cpp delete mode 100644 test/model/RangeSet.cpp delete mode 100644 test/model/domain/Layer.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a1a3e2..8c59356 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,9 +21,6 @@ PROJECT(basicwriter) CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9) -SET(CMAKE_AUTOMOC ON) -FIND_PACKAGE(Qt5Core REQUIRED) - # Option for enabling testing. Turn on with 'cmake -Dtest=ON'. OPTION(test "Build all tests." OFF) # Makes boolean 'test' available. @@ -54,50 +51,19 @@ INCLUDE_DIRECTORIES( src/ ) -# ousia_model library (containing the code of the most important data structures -# and deduction algorithms -- this code does not depend on Qt). -ADD_LIBRARY(ousia_model - src/model/GraphNode - src/model/domain/Domain - src/model/domain/Structure - src/model/domain/ClassCategory - src/model/domain/Class - src/model/domain/ClassReferenceSet - src/model/domain/ClassReference - src/model/domain/Layer - src/model/domain/AnnotationReference - src/model/domain/Field - src/model/domain/AnnotationCategory - src/model/domain/Annotation - src/model/types/Type -) - -# ousia_xml library (containing the XML serialization/deserializing code for the -# data structures defined in the ousia_model library) -ADD_LIBRARY(ousia_xml - src/xml/XmlReader -) - -TARGET_LINK_LIBRARIES(ousia_xml - ousia_model +# ousia_script library (containing the code of t +ADD_LIBRARY(ousia_script + src/core/script/Variant.cpp ) -# Link the ousia xml model against the core module of Qt5 -QT5_USE_MODULES(ousia_xml Core Script) - # Definition of the main program -ADD_EXECUTABLE(ousia - src/main -) +#ADD_EXECUTABLE(ousia +#) # Link the ousia executable against ousia_core -TARGET_LINK_LIBRARIES(ousia - ousia_model - ousia_xml -) - -# Link the ousia executable against the Widgets module of Qt5 -QT5_USE_MODULES(ousia Widgets) +#TARGET_LINK_LIBRARIES(ousia +# ousia_script +#) # If testing is enabled, build the unit tests IF(test) @@ -109,14 +75,12 @@ IF(test) # Add all unit test files ADD_EXECUTABLE(ousia_test - test/model/RangeSet - test/model/GraphNode + test/core/model/RangeSet ) TARGET_LINK_LIBRARIES(ousia_test ${GTEST_LIBRARIES} - ousia_model - ousia_xml + ousia_script ) # Register the unit test diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..18170aa --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cd build && cmake .. -Dtest=on && make && make test + diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..718a5a7 --- /dev/null +++ b/clean.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +find build/ -depth -mindepth 1 -delete -print + +find -depth \( \( -name "*.aux" -o -name "*.snm" -o -name "*.out" -o -name "*.toc" -o -name "*.nav" -o -name "*.log" -o -name "*.backup" -o -name "*.bbl" -o -name "*.blg" -o -name "*~" \) -a \! \( -wholename "*.git/*" -o -wholename "*.svn" \) \) -delete -print diff --git a/dependencies.txt b/dependencies.txt index 1939fef..9957d04 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -1,6 +1,6 @@ The following packages have to be installed (for Fedora) - cmake -- qt5-qtbase-devel -- qt5-qtscript-devel +# - qt5-qtbase-devel (not needed for now) +# - qt5-qtscript-devel (not needed for now) diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 3603b9c..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -using namespace ousia::xml; - -int main(int argc, char *argv[]) -{ - QScriptEngine engine; - qDebug() << "JS Test: " << engine.evaluate("Test"); - - // Open the file given as first argument -// if (argc < 2) { -// std::cout << "No filename specified!" << std::endl; -// return 1; -// } - -// QFile file(argv[1]); -// if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { -// std::cout << "Error while opening file " << argv[1] << std::endl; -// return 1; -// } - - // Create the QXmlStreamReader instance -// QXmlStreamReader xml(&file); - - // Pass it to the XmlReader -// XmlReader xmlReader(xml); -// xmlReader.process(); - - return 0; -} - diff --git a/test/core/model/RangeSet.cpp b/test/core/model/RangeSet.cpp new file mode 100644 index 0000000..4f04538 --- /dev/null +++ b/test/core/model/RangeSet.cpp @@ -0,0 +1,222 @@ +/* + Ousía + Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +#include + +namespace ousia { +namespace model { + +TEST(Range, IsValid) +{ + ASSERT_FALSE(Range().isValid()); + ASSERT_TRUE(Range(10).isValid()); + ASSERT_TRUE(Range(10, 20).isValid()); + ASSERT_FALSE(Range(20, 10).isValid()); +} + +TEST(Range, InRange) +{ + Range r(10, 20); + ASSERT_FALSE(r.inRange(0)); + ASSERT_FALSE(r.inRange(21)); + ASSERT_TRUE(r.inRange(10)); + ASSERT_TRUE(r.inRange(20)); + ASSERT_TRUE(r.inRange(15)); +} + +TEST(Range, Overlapps) +{ + ASSERT_FALSE(Range(10, 20).overlapps(Range(0, 9))); + ASSERT_FALSE(Range(10, 20).overlapps(Range(21, 30))); + ASSERT_TRUE(Range(10, 20).overlapps(Range(0, 10))); + ASSERT_TRUE(Range(10, 20).overlapps(Range(20, 30))); + ASSERT_TRUE(Range(10, 20).overlapps(Range(5, 15))); + ASSERT_TRUE(Range(10, 20).overlapps(Range(15, 25))); + ASSERT_TRUE(Range(10, 20).overlapps(Range(15, 19))); + ASSERT_TRUE(Range(10, 20).overlapps(Range(15, 15))); + ASSERT_TRUE(Range(10, 20).overlapps(Range(10, 20))); + ASSERT_TRUE(Range(10, 20).overlapps(Range(0, 30))); +} + +TEST(Range, CoveredBy) +{ + ASSERT_FALSE(Range(10, 20).coveredBy(Range(0, 9))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(21, 30))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(0, 10))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(20, 30))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(5, 15))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 25))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 19))); + ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 15))); + ASSERT_TRUE(Range(10, 20).coveredBy(Range(10, 20))); + ASSERT_TRUE(Range(10, 20).coveredBy(Range(0, 30))); +} + +TEST(Range, Covers) +{ + ASSERT_FALSE(Range(10, 20).covers(Range(0, 9))); + ASSERT_FALSE(Range(10, 20).covers(Range(21, 30))); + ASSERT_FALSE(Range(10, 20).covers(Range(0, 10))); + ASSERT_FALSE(Range(10, 20).covers(Range(20, 30))); + ASSERT_FALSE(Range(10, 20).covers(Range(5, 15))); + ASSERT_FALSE(Range(10, 20).covers(Range(15, 25))); + ASSERT_TRUE(Range(10, 20).covers(Range(15, 19))); + ASSERT_TRUE(Range(10, 20).covers(Range(15, 15))); + ASSERT_TRUE(Range(10, 20).covers(Range(10, 20))); + ASSERT_FALSE(Range(10, 20).covers(Range(0, 30))); +} + +TEST(RangeSet, Neighbours) +{ + ASSERT_TRUE(Range(10, 19).neighbours(Range(20, 30))); + ASSERT_TRUE(Range(20, 29).neighbours(Range(10, 19))); +} + +TEST(Range, Merge) +{ + Range r1(10, 20); + Range r2(15, 25); + Range r3(5, 15); + Range rM = r1.merge(r2).merge(r3); + ASSERT_EQ(rM.start, 5); + ASSERT_EQ(rM.end, 25); +} + +TEST(RangeSet, Merge) +{ + RangeSet s; + auto &ranges = s.getRanges(); + + // Insert some non-overlapping elements into the range. We expect these to + // be just inserted into the ranges. + s.merge(Range( 0, 10)); + s.merge(Range(20, 30)); + s.merge(Range(40, 50)); + s.merge(Range(60, 70)); + { + ASSERT_EQ(ranges.size(), 4); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, 0); + ASSERT_EQ((*it).end, 10); + + it++; + ASSERT_EQ((*it).start, 20); + ASSERT_EQ((*it).end, 30); + + it++; + ASSERT_EQ((*it).start, 40); + ASSERT_EQ((*it).end, 50); + + it++; + ASSERT_EQ((*it).start, 60); + ASSERT_EQ((*it).end, 70); + } + + // Now insert an element which spans the second and third element + s.merge(Range(15, 55)); + { + ASSERT_EQ(ranges.size(), 3); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, 0); + ASSERT_EQ((*it).end, 10); + + it++; + ASSERT_EQ((*it).start, 15); + ASSERT_EQ((*it).end, 55); + + it++; + ASSERT_EQ((*it).start, 60); + ASSERT_EQ((*it).end, 70); + } + + // Now insert an element which expands the first element + s.merge(Range(-10, 11)); + { + ASSERT_EQ(ranges.size(), 3); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, -10); + ASSERT_EQ((*it).end, 11); + + it++; + ASSERT_EQ((*it).start, 15); + ASSERT_EQ((*it).end, 55); + + it++; + ASSERT_EQ((*it).start, 60); + ASSERT_EQ((*it).end, 70); + } + + // Now insert an element which merges the last two elements + s.merge(Range(13, 70)); + { + ASSERT_EQ(ranges.size(), 2); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, -10); + ASSERT_EQ((*it).end, 11); + + it++; + ASSERT_EQ((*it).start, 13); + ASSERT_EQ((*it).end, 70); + } + + // Now insert an element which merges the remaining elements + s.merge(Range(-9, 12)); + { + ASSERT_EQ(ranges.size(), 1); + + auto it = ranges.begin(); + ASSERT_EQ((*it).start, -10); + ASSERT_EQ((*it).end, 70); + } + +} + +TEST(RangeSet, Contains) +{ + RangeSet s; + + // Insert some non-overlapping elements into the range. We expect these to + // be just inserted into the ranges. + s.merge(Range( 0, 10)); + s.merge(Range(20, 30)); + s.merge(Range(40, 50)); + s.merge(Range(60, 70)); + s.merge(Range(71)); + s.merge(Range(72)); + s.merge(Range(73)); + s.merge(Range(74)); + + ASSERT_TRUE(s.contains(60)); + ASSERT_TRUE(s.contains(0)); + ASSERT_TRUE(s.contains(25)); + ASSERT_TRUE(s.contains(73)); + ASSERT_TRUE(s.contains(Range(25, 30))); + ASSERT_FALSE(s.contains(Range(25, 35))); + ASSERT_TRUE(s.contains(Range(0, 10))); + ASSERT_TRUE(s.contains(Range(70, 74))); +} + +} +} + diff --git a/test/model/GraphNode.cpp b/test/model/GraphNode.cpp deleted file mode 100644 index bdb633c..0000000 --- a/test/model/GraphNode.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - Ousía - Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include - -namespace ousia { -namespace model { - -// Make the protected constructor of GraphNode available -class TestGraphNode : public GraphNode { - -public: - TestGraphNode(GraphNodeType type, std::shared_ptr parent, - const std::string &name) : - GraphNode(type, parent, name) - { - // Do nothing here - } - -}; - -TEST(GraphNodeTest, FullyQuallifiedNameTest) -{ - std::shared_ptr nd1{new TestGraphNode( - GraphNodeType::Domain, nullptr, "node1")}; - std::shared_ptr nd2{new TestGraphNode( - GraphNodeType::Domain, nd1, "node2")}; - - ASSERT_STREQ("node1.node2", nd2->getFullyQualifiedName().c_str()); -} - -} -} - diff --git a/test/model/RangeSet.cpp b/test/model/RangeSet.cpp deleted file mode 100644 index d026025..0000000 --- a/test/model/RangeSet.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - Ousía - Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include - -namespace ousia { -namespace model { - -TEST(Range, IsValid) -{ - ASSERT_FALSE(Range().isValid()); - ASSERT_TRUE(Range(10).isValid()); - ASSERT_TRUE(Range(10, 20).isValid()); - ASSERT_FALSE(Range(20, 10).isValid()); -} - -TEST(Range, InRange) -{ - Range r(10, 20); - ASSERT_FALSE(r.inRange(0)); - ASSERT_FALSE(r.inRange(21)); - ASSERT_TRUE(r.inRange(10)); - ASSERT_TRUE(r.inRange(20)); - ASSERT_TRUE(r.inRange(15)); -} - -TEST(Range, Overlapps) -{ - ASSERT_FALSE(Range(10, 20).overlapps(Range(0, 9))); - ASSERT_FALSE(Range(10, 20).overlapps(Range(21, 30))); - ASSERT_TRUE(Range(10, 20).overlapps(Range(0, 10))); - ASSERT_TRUE(Range(10, 20).overlapps(Range(20, 30))); - ASSERT_TRUE(Range(10, 20).overlapps(Range(5, 15))); - ASSERT_TRUE(Range(10, 20).overlapps(Range(15, 25))); - ASSERT_TRUE(Range(10, 20).overlapps(Range(15, 19))); - ASSERT_TRUE(Range(10, 20).overlapps(Range(15, 15))); - ASSERT_TRUE(Range(10, 20).overlapps(Range(10, 20))); - ASSERT_TRUE(Range(10, 20).overlapps(Range(0, 30))); -} - -TEST(Range, CoveredBy) -{ - ASSERT_FALSE(Range(10, 20).coveredBy(Range(0, 9))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(21, 30))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(0, 10))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(20, 30))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(5, 15))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 25))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 19))); - ASSERT_FALSE(Range(10, 20).coveredBy(Range(15, 15))); - ASSERT_TRUE(Range(10, 20).coveredBy(Range(10, 20))); - ASSERT_TRUE(Range(10, 20).coveredBy(Range(0, 30))); -} - -TEST(Range, Covers) -{ - ASSERT_FALSE(Range(10, 20).covers(Range(0, 9))); - ASSERT_FALSE(Range(10, 20).covers(Range(21, 30))); - ASSERT_FALSE(Range(10, 20).covers(Range(0, 10))); - ASSERT_FALSE(Range(10, 20).covers(Range(20, 30))); - ASSERT_FALSE(Range(10, 20).covers(Range(5, 15))); - ASSERT_FALSE(Range(10, 20).covers(Range(15, 25))); - ASSERT_TRUE(Range(10, 20).covers(Range(15, 19))); - ASSERT_TRUE(Range(10, 20).covers(Range(15, 15))); - ASSERT_TRUE(Range(10, 20).covers(Range(10, 20))); - ASSERT_FALSE(Range(10, 20).covers(Range(0, 30))); -} - -TEST(RangeSet, Neighbours) -{ - ASSERT_TRUE(Range(10, 19).neighbours(Range(20, 30))); - ASSERT_TRUE(Range(20, 29).neighbours(Range(10, 19))); -} - -TEST(Range, Merge) -{ - Range r1(10, 20); - Range r2(15, 25); - Range r3(5, 15); - Range rM = r1.merge(r2).merge(r3); - ASSERT_EQ(rM.start, 5); - ASSERT_EQ(rM.end, 25); -} - -TEST(RangeSet, Merge) -{ - RangeSet s; - auto &ranges = s.getRanges(); - - // Insert some non-overlapping elements into the range. We expect these to - // be just inserted into the ranges. - s.merge(Range( 0, 10)); - s.merge(Range(20, 30)); - s.merge(Range(40, 50)); - s.merge(Range(60, 70)); - { - ASSERT_EQ(ranges.size(), 4); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, 0); - ASSERT_EQ((*it).end, 10); - - it++; - ASSERT_EQ((*it).start, 20); - ASSERT_EQ((*it).end, 30); - - it++; - ASSERT_EQ((*it).start, 40); - ASSERT_EQ((*it).end, 50); - - it++; - ASSERT_EQ((*it).start, 60); - ASSERT_EQ((*it).end, 70); - } - - // Now insert an element which spans the second and third element - s.merge(Range(15, 55)); - { - ASSERT_EQ(ranges.size(), 3); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, 0); - ASSERT_EQ((*it).end, 10); - - it++; - ASSERT_EQ((*it).start, 15); - ASSERT_EQ((*it).end, 55); - - it++; - ASSERT_EQ((*it).start, 60); - ASSERT_EQ((*it).end, 70); - } - - // Now insert an element which expands the first element - s.merge(Range(-10, 11)); - { - ASSERT_EQ(ranges.size(), 3); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, -10); - ASSERT_EQ((*it).end, 11); - - it++; - ASSERT_EQ((*it).start, 15); - ASSERT_EQ((*it).end, 55); - - it++; - ASSERT_EQ((*it).start, 60); - ASSERT_EQ((*it).end, 70); - } - - // Now insert an element which merges the last two elements - s.merge(Range(13, 70)); - { - ASSERT_EQ(ranges.size(), 2); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, -10); - ASSERT_EQ((*it).end, 11); - - it++; - ASSERT_EQ((*it).start, 13); - ASSERT_EQ((*it).end, 70); - } - - // Now insert an element which merges the remaining elements - s.merge(Range(-9, 12)); - { - ASSERT_EQ(ranges.size(), 1); - - auto it = ranges.begin(); - ASSERT_EQ((*it).start, -10); - ASSERT_EQ((*it).end, 70); - } - -} - -TEST(RangeSet, Contains) -{ - RangeSet s; - - // Insert some non-overlapping elements into the range. We expect these to - // be just inserted into the ranges. - s.merge(Range( 0, 10)); - s.merge(Range(20, 30)); - s.merge(Range(40, 50)); - s.merge(Range(60, 70)); - s.merge(Range(71)); - s.merge(Range(72)); - s.merge(Range(73)); - s.merge(Range(74)); - - ASSERT_TRUE(s.contains(60)); - ASSERT_TRUE(s.contains(0)); - ASSERT_TRUE(s.contains(25)); - ASSERT_TRUE(s.contains(73)); - ASSERT_TRUE(s.contains(Range(25, 30))); - ASSERT_FALSE(s.contains(Range(25, 35))); - ASSERT_TRUE(s.contains(Range(0, 10))); - ASSERT_TRUE(s.contains(Range(70, 74))); -} - -} -} - diff --git a/test/model/domain/Layer.cpp b/test/model/domain/Layer.cpp deleted file mode 100644 index 89aeaa4..0000000 --- a/test/model/domain/Layer.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - Ousía - Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include -#include - -#include -#include - -namespace ousia { -namespace domain{ - -TEST(LayerTest, AnnotationManagementTest) -{ - std::shared_ptr anno1{new Annotation("em1")}; - std::shared_ptr anno2{new Annotation("em2", anno1)}; - - Layer layer {"layer"}; - - std::vector>& annos = layer.getAnnotations(); - - annos.push_back(anno1); - annos.push_back(anno2); - - std::vector>& test_annos = layer.getAnnotations(); - - ASSERT_EQ(2, test_annos.size()); - ASSERT_EQ(anno1, test_annos[0]); - ASSERT_EQ(anno2, test_annos[1]); -} - -} -} -- cgit v1.2.3