From c6bb5ad9f779e8b40d167b749688b4b45d73a758 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Wed, 14 May 2014 20:33:53 +0200
Subject: [PATCH] test factory classes

---
 alib2/test-src/automaton/AutomatonTest.cpp | 31 ++++++++++++++-------
 alib2/test-src/regexp/RegExpTest.cpp       | 32 ++++++++++++++--------
 2 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/alib2/test-src/automaton/AutomatonTest.cpp b/alib2/test-src/automaton/AutomatonTest.cpp
index 5d5c658714..4670477bf3 100644
--- a/alib2/test-src/automaton/AutomatonTest.cpp
+++ b/alib2/test-src/automaton/AutomatonTest.cpp
@@ -8,6 +8,8 @@
 #include "automaton/AutomatonFromXMLParser.h"
 #include "automaton/AutomatonToXMLComposer.h"
 
+#include "factory/AutomatonFactory.h"
+
 #define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y))
 
 CPPUNIT_TEST_SUITE_REGISTRATION( AutomatonTest );
@@ -24,17 +26,26 @@ void AutomatonTest::testXMLParser() {
   automaton.setInputSymbols({alphabet::Symbol("a"), alphabet::Symbol("b")});
   automaton.addTransition(automaton::UnknownTransition());
   
-  automaton::AutomatonToXMLComposer composer;
-  std::list<sax::Token> tokens = composer.compose(automaton);
-  std::string tmp;
-  sax::SaxComposeInterface::printMemory(tmp, tokens);
+  CPPUNIT_ASSERT( automaton == automaton );
+  {
+	automaton::AutomatonToXMLComposer composer;
+	std::list<sax::Token> tokens = composer.compose(automaton);
+	std::string tmp;
+	sax::SaxComposeInterface::printMemory(tmp, tokens);
   
-  std::list<sax::Token> tokens2;
-  sax::SaxParseInterface::parseMemory(tmp, tokens2);
-  automaton::AutomatonFromXMLParser parser;
-  automaton::UnknownAutomaton automaton2 = parser.parse(tokens2);
+	std::list<sax::Token> tokens2;
+	sax::SaxParseInterface::parseMemory(tmp, tokens2);
+	automaton::AutomatonFromXMLParser parser;
+	automaton::UnknownAutomaton automaton2 = parser.parse(tokens2);
 
-  CPPUNIT_ASSERT( automaton == automaton );
-  CPPUNIT_ASSERT( automaton == automaton2 );
+	CPPUNIT_ASSERT( automaton == automaton2 );
+  }
+  {
+	std::string tmp = automaton::AutomatonFactory::toString(automaton);
+	automaton::UnknownAutomaton automaton2 = automaton::AutomatonFactory::fromString(tmp);
+
+	CPPUNIT_ASSERT( automaton == automaton2 );
+
+  }
 }
 
diff --git a/alib2/test-src/regexp/RegExpTest.cpp b/alib2/test-src/regexp/RegExpTest.cpp
index a4cdd33d21..b330ccf717 100644
--- a/alib2/test-src/regexp/RegExpTest.cpp
+++ b/alib2/test-src/regexp/RegExpTest.cpp
@@ -10,6 +10,8 @@
 #include "regexp/RegExpFromXMLParser.h"
 #include "regexp/RegExpToXMLComposer.h"
 
+#include "factory/RegExpFactory.h"
+
 #define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y))
 
 CPPUNIT_TEST_SUITE_REGISTRATION( RegExpTest );
@@ -73,17 +75,25 @@ void RegExpTest::testXMLParser() {
 			   )
 		       );
 
-  regexp::RegExpToXMLComposer composer;
-  std::list<sax::Token> tokens = composer.compose(regexp);
-  std::string tmp;
-  sax::SaxComposeInterface::printMemory(tmp, tokens);
-  
-  std::list<sax::Token> tokens2;
-  sax::SaxParseInterface::parseMemory(tmp, tokens2);
-  regexp::RegExpFromXMLParser parser;
-  regexp::RegExp regexp2 = parser.parse(tokens2);
-  
-  CPPUNIT_ASSERT( regexp == regexp2 );
+  {
+	regexp::RegExpToXMLComposer composer;
+	std::list<sax::Token> tokens = composer.compose(regexp);
+	std::string tmp;
+	sax::SaxComposeInterface::printMemory(tmp, tokens);
+  
+	std::list<sax::Token> tokens2;
+	sax::SaxParseInterface::parseMemory(tmp, tokens2);
+	regexp::RegExpFromXMLParser parser;
+	regexp::RegExp regexp2 = parser.parse(tokens2);
+  
+	CPPUNIT_ASSERT( regexp == regexp2 );
+  }
+  {
+	std::string tmp = regexp::RegExpFactory::toString(regexp);
+	regexp::RegExp regexp2 = regexp::RegExpFactory::fromString(tmp);
+  
+	CPPUNIT_ASSERT( regexp == regexp2 );
+  }
 }
 
 void RegExpTest::testOrder() {
-- 
GitLab