Fix importers/exporters bugs. Fix tests and add them to build process.

The file `mx2test.txt` is taken from KRecipes 2.1 source code.
Other tests have been adjusted based on the tests in KRecipes 2.1 source code.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
pull/30/head
Michele Calgaro 7 months ago
parent fd118e52e5
commit dfbafdbb2f
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -27,6 +27,7 @@ include( CheckIncludeFile )
include( CheckLibraryExists )
include( CheckCSourceCompiles )
include( CheckCXXSourceCompiles )
enable_testing()
#### include our cmake modules

@ -200,7 +200,7 @@ void RezkonvExporter::writeIngredients( TQString &content, const Recipe &recipe
TQString authorLines;
if ( recipe.authorList.count() > 0 ) {
content += "============================== TQUELLE ==============================\n";
content += "============================== QUELLE ==============================\n";
authorLines = " "+(*recipe.authorList.begin()).name+"\n";
}
for ( ElementList::const_iterator author_it = ++recipe.authorList.begin(); author_it != recipe.authorList.end(); ++author_it ) {
@ -266,7 +266,7 @@ void RezkonvExporter::writeSingleIngredient( TQString &content, const Ingredient
//columns 21-70
TQString ing_name( ing.name );
if ( ing.prepMethodList.count() > 0 )
ing_name += "; " + ing.prepMethodList.join(", ");
ing_name += ", " + ing.prepMethodList.join(", ");
if ( is_sub )
ing_name += ", or"; //FIXME: what's 'or' in German?

@ -26,7 +26,9 @@ Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307 USA
#include <tqstringlist.h>
#include <tqtextstream.h>
#include <tqdatetime.h>
#include <tqvalidator.h>
#include "datablocks/mixednumber.h"
#include "datablocks/recipe.h"
@ -115,17 +117,40 @@ void MX2Importer::readRecipe( const TQDomNodeList& l, Recipe *recipe )
}
}
else if ( tagName == "IngR" ) {
double quantity1=0, quantity2=0, offset=0;
TQStringList qtyStrList = TQStringList::split( ' ', el.attribute( "qty" ) );
if ( !qtyStrList.isEmpty() ) {
TQValidator::State state;
MixedNumber number;
bool ok;
number = MixedNumber::fromString( qtyStrList.first(), &ok, false );
if ( !ok )
quantity1 = 0;
else
quantity1 = number.toDouble();
number = MixedNumber::fromString( qtyStrList.last(), &ok, false );
if ( !ok )
quantity2 = 0;
else
quantity2 = number.toDouble();
}
offset = quantity2 - quantity1;
Ingredient new_ing( el.attribute( "name" ),
el.attribute( "qty" ).toDouble(),
Unit( el.attribute( "unit" ), el.attribute( "qty" ).toDouble() ) );
quantity1,
Unit( el.attribute( "unit" ), quantity1 ) );
new_ing.amount_offset = offset;
if ( el.hasChildNodes() ) {
TQDomNodeList iChilds = el.childNodes();
for ( unsigned j = 0; j < iChilds.count(); j++ ) {
for ( int j = 0; j < iChilds.count(); j++ ) {
TQDomElement iChild = iChilds.item( j ).toElement();
if ( iChild.tagName() == "IPrp" )
new_ing.prepMethodList.append( Element(iChild.text().stripWhiteSpace()) );
else if ( iChild.tagName() == "INtI" )
if ( iChild.tagName() == "IPrp" ) {
TQString prepMethodStr = iChild.text().stripWhiteSpace();
if ( !prepMethodStr.isEmpty() )
new_ing.prepMethodList.append( Element( prepMethodStr ) );
}
else if ( iChild.tagName() == "INtI" ) {
; // TODO: What does it mean?... ingredient nutrient info?
}
}
}
recipe->ingList.append( new_ing );

@ -142,7 +142,7 @@ void MXPImporter::loadCategories( TQTextStream &stream, Recipe &recipe )
while ( current.stripWhiteSpace() != "Amount Measure Ingredient -- Preparation Method" && !stream.atEnd() ) {
if ( !tmp_str.isEmpty() ) {
TQStringList categories = TQStringList::split( " ", tmp_str );
TQStringList categories = TQStringList::split( "\t", tmp_str );
for ( TQStringList::const_iterator it = categories.begin(); it != categories.end(); ++it ) {
Element new_cat( ( *it ).stripWhiteSpace() );
recipe.categoryList.append( new_cat );

@ -198,6 +198,7 @@ void RezkonvImporter::loadInstructions( TQStringList::const_iterator &text_it, R
TQString instr;
TQRegExp rx_title( "^:{0,1}\\s*O-Titel\\s*:" );
TQString line;
text_it++;
while ( text_it != m_end_it ) {
line = *text_it;
@ -216,12 +217,8 @@ void RezkonvImporter::loadInstructions( TQStringList::const_iterator &text_it, R
kdDebug() << "Found long title: " << recipe.title << endl;
}
else {
if ( line.isEmpty() )
instr += "\n\n";
instr += line;
instr += line.stripWhiteSpace();
}
text_it++;
}

@ -16,78 +16,112 @@ link_directories(
)
##### A function to copy required test files to binary folder
function( setup_test_data _target )
unset(_sources)
unset(_copies)
foreach( _file ${ARGN} )
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
COMMENT "Copying test data: ${_file}"
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/${_file}
${CMAKE_CURRENT_BINARY_DIR}
)
list(APPEND _sources ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
list(APPEND _copies ${CMAKE_CURRENT_BINARY_DIR}/${_file})
endforeach( )
add_custom_target( ${_target}_testdata
SOURCES ${_sources}
DEPENDS ${_copies}
)
add_dependencies( ${_target} ${_target}_testdata )
endfunction()
##### kretest (executable)
tde_add_check_executable( kretest AUTOMOC
tde_add_check_executable( kretest AUTOMOC TEST
SOURCES kretest.cpp
LINK
krecipesexporters-static krecipesimporters-static
krecipesdbs-static datablocks-static
tdecore-shared tdeio-shared
)
setup_test_data( kretest kretest.txt test_photo.jpg )
##### mmftest (executable)
tde_add_check_executable( mmftest AUTOMOC
tde_add_check_executable( mmftest AUTOMOC TEST
SOURCES mmftest.cpp
LINK
krecipesexporters-static krecipesimporters-static
krecipesdbs-static datablocks-static
tdecore-shared tdeio-shared
)
setup_test_data( mmftest mmftest.txt )
##### mx2test (executable)
tde_add_check_executable( mx2test AUTOMOC
tde_add_check_executable( mx2test AUTOMOC TEST
SOURCES mx2test.cpp
LINK
krecipesexporters-static krecipesimporters-static
krecipesdbs-static datablocks-static
tdecore-shared tdeio-shared
)
setup_test_data( mx2test mx2test.txt )
##### mxptest (executable)
tde_add_check_executable( mxptest AUTOMOC
tde_add_check_executable( mxptest AUTOMOC TEST
SOURCES mxptest.cpp
LINK
krecipesexporters-static krecipesimporters-static
krecipesdbs-static datablocks-static
tdecore-shared tdeio-shared
)
setup_test_data( mxptest mxptest.txt )
##### rezkonvtest (executable)
##### nyctest (executable)
tde_add_check_executable( rezkonvtest AUTOMOC
SOURCES rezkonvtest.cpp
tde_add_check_executable( nyctest AUTOMOC TEST
SOURCES nyctest.cpp
LINK
krecipesexporters-static krecipesimporters-static
krecipesdbs-static datablocks-static
tdecore-shared tdeio-shared
)
setup_test_data( nyctest nyctest.txt )
##### nyctest (executable)
##### recipemltest (executable)
tde_add_check_executable( nyctest AUTOMOC
SOURCES nyctest.cpp
tde_add_check_executable( recipemltest AUTOMOC TEST
SOURCES recipemltest.cpp
LINK
krecipesexporters-static krecipesimporters-static
krecipesdbs-static datablocks-static
tdecore-shared tdeio-shared
)
setup_test_data( recipemltest recipemltest.txt )
##### recipemltest (executable)
##### rezkonvtest (executable)
tde_add_check_executable( recipemltest AUTOMOC
SOURCES recipemltest.cpp
tde_add_check_executable( rezkonvtest AUTOMOC TEST
SOURCES rezkonvtest.cpp
LINK
krecipesexporters-static krecipesimporters-static
krecipesdbs-static datablocks-static
tdecore-shared tdeio-shared
)
setup_test_data( rezkonvtest rezkonvtest.txt )

@ -30,10 +30,10 @@ void check( const RatingList &rating, const RatingList &base );
bool check(const TQString &txt, const TQString &a, const TQString &b)
{
if ( a != b ) {
cout << "ERROR: Tested " << txt.latin1() << ", expected" << endl;
cout << "'" << b.latin1() << "' (" << b.length() << " chars)" << endl;
cout << "ERROR: Tested " << txt.local8Bit() << ", expected" << endl;
cout << "'" << b.local8Bit() << "' (" << b.length() << " chars)" << endl;
cout << "but got" << endl;
cout << "'" << a.latin1() << "' (" << a.length() << " chars)" << endl;
cout << "'" << a.local8Bit() << "' (" << a.length() << " chars)" << endl;
exit( 1 );
}
@ -43,7 +43,7 @@ bool check(const TQString &txt, const TQString &a, const TQString &b)
bool check(const TQString &txt, int a, int b)
{
if ( a != b ) {
cout << "ERROR: Tested " << txt.latin1() << ", expected" << endl;
cout << "ERROR: Tested " << txt.local8Bit() << ", expected" << endl;
cout << "'" << b << "'" << endl;
cout << "but got" << endl;
cout << "'" << a << "'" << endl;
@ -56,7 +56,7 @@ bool check(const TQString &txt, int a, int b)
bool check(const TQString &txt, double a, double b)
{
if ( fabs(a - b) > 1e-10 ) {
cout << "ERROR: Tested " << txt.latin1() << ", expected" << endl;
cout << "ERROR: Tested " << txt.local8Bit() << ", expected" << endl;
cout << "'" << b << "'" << endl;
cout << "but got" << endl;
cout << "'" << a << "'" << endl;
@ -70,7 +70,7 @@ bool check(const TQString &txt, const TQPixmap &a, const TQPixmap &b)
{
if ( a.size() != b.size() ) {
cout << "ERROR: Tested " << txt.latin1() << ": photos differ" << endl;
cout << "ERROR: Tested " << txt.local8Bit() << ": photos differ" << endl;
// exit( 1 );
}

@ -24,9 +24,9 @@ using std::cout;
using std::cerr;
using std::endl;
void check( BaseExporter &exporter, const RecipeList &recipeList )
void check( const char *filename, BaseExporter &exporter, const RecipeList &recipeList )
{
TQFile file("test.txt");
TQFile file(filename);
if ( file.open( IO_WriteOnly ) ) {
TQTextStream stream(&file);
exporter.writeStream(stream,recipeList);

@ -167,7 +167,6 @@ main(int argc, char *argv[])
recipe.ratingList.append(rating1);
recipe.ratingList.append(rating2);
check( importer, recipe );
check( importer, catTree );
@ -178,16 +177,16 @@ main(int argc, char *argv[])
printf("Creating KreExporter.\n");
KreExporter exporter(catTree,"not needed",".kreml");
check( exporter, recipeList );
printf("Successfully exported recipes to test.txt.\n");
const char *outfile = "kretest_output.txt";
check( outfile, exporter, recipeList );
printf("Successfully exported recipes to %s.\n", outfile);
printf("Creating KreImporter to test exported recipes.\n");
KreImporter importer2;
printf("Parsing test.txt.\n");
TQStringList files2; files2 << "test.txt";
printf("Parsing %s.\n", outfile);
TQStringList files2; files2 << TQString(outfile);
importer2.parseFiles(files2);
TQFile::remove("test.txt");
check( importer2, recipe );
check( importer2, catTree );
printf("Recipe export successful.\n");

@ -118,7 +118,6 @@ main(int argc, char *argv[])
ing7.groupID = 1; ing7.group = "Fat & Liquids";
recipe.ingList.append( ing7 );
check( importer, recipe );
RecipeList recipeList;
@ -127,16 +126,16 @@ main(int argc, char *argv[])
printf("Creating MMFExporter.\n");
MMFExporter exporter("not needed",".mmf");
check( exporter, recipeList );
const char *outfile = "mmftest_output.txt";
check( outfile, exporter, recipeList );
printf("Successfully exported recipes to test.txt.\n");
printf("Creating MMFImporter to test exported recipes.\n");
MMFImporter importer2;
printf("Parsing test.txt.\n");
TQStringList files2; files2 << "test.txt";
printf("Parsing %s.\n", outfile);
TQStringList files2; files2 << TQString(outfile);
importer2.parseFiles(files2);
TQFile::remove("test.txt");
check( importer2, recipe );
printf("Recipe export successful.\n");

@ -13,6 +13,7 @@
#include <tdecmdlineargs.h>
#include <tqstring.h>
#include <tqfile.h>
#include <iostream>
using std::cout;
@ -37,41 +38,73 @@ main(int argc, char *argv[])
importer.parseFiles(files);
Recipe recipe;
recipe.title = "Title 1";
recipe.title = "Cookies Test";
recipe.yield.amount = 2;
recipe.yield.type = "servings";
recipe.categoryList.append( Element("Category 1") );
recipe.categoryList.append( Element("Category 2") );
recipe.categoryList.append( Element("Snacks",1) );
recipe.categoryList.append( Element("Cookies & Squares",2) );
recipe.instructions =
"Instruction line 1\n"
"Instruction line 2\n"
"Instruction line 3";
"1. Drop by spoonful on greased cookie sheet.\n"
"\n"
"2. Bake in moderate oven.";
recipe.prepTime = TQTime(0,30);
recipe.authorList.append( Element("Colleen Beamer") );
Ingredient ing;
ing.name = "ingredient 1";
ing.amount = 1;
ing.units.name = "teaspoon";
ing.name = "granulated sugar";
ing.amount = 0.75;
ing.amount_offset = 0.25;
ing.units.name = "c.";
recipe.ingList.append( ing );
Ingredient ing2;
ing2.name = "ingredient 2";
ing2.amount = 3.5;
ing2.units.plural = TQString::null;
ing2.name = "brown sugar";
ing2.amount = 0.75;
ing2.amount_offset = 0.25;
ing2.units.name = "c.";
recipe.ingList.append( ing2 );
Ingredient ing3;
ing3.name = "ingredient 3";
ing3.amount = 3.5;
ing3.units.plural = "ounces";
ing3.name = "all-purpose flour";
ing3.amount = 2;
ing3.units.plural = "c.";
recipe.ingList.append( ing3 );
Ingredient ing4;
ing4.name = "ingredient 4";
ing4.amount = 3.5;
ing4.units.plural = "ounces";
ing4.name = "baking soda";
ing4.amount = 1;
ing4.units.name = "tsp.";
recipe.ingList.append( ing4 );
Ingredient ing8;
ing8.name = "shortening";
ing8.amount = 1;
ing8.units.name = "c.";
ing8.prepMethodList.append( Element("softened, at room temperature") );
recipe.ingList.append( ing8 );
Ingredient ing6;
ing6.name = "peanut butter";
ing6.amount = 1;
ing6.units.name = "c.";
recipe.ingList.append( ing6 );
Ingredient ing5;
ing5.name = "eggs";
ing5.amount = 2;
ing5.units.plural = "";
recipe.ingList.append( ing5 );
Ingredient ing7;
ing7.name = "vanilla extract";
ing7.amount = 1;
ing7.units.name = "tsp.";
recipe.ingList.append( ing7 );
check( importer, recipe );
printf("*** mx2 importer passed the tests :-) ***\n");
printf("Done.\n");
}

@ -0,0 +1,115 @@
<?xml version="1.0" standalone="yes" encoding="ISO-8859-1"?>
<!DOCTYPE mx2 SYSTEM "mx2.dtd">
<mx2 source="my mind" date="Oct 22, 2009">
<Summ><Nam>Summary name</Nam></Summ> <!-- NOT SUPPORTED -->
<RcpE name="Cookies Test" author="Colleen Beamer">
<Serv qty="2"/><PrpT elapsed="0:30"/>
<CatS>
<CatT>Snacks</CatT>
<CatT>Cookies &amp; Squares</CatT>
</CatS>
<IngR name="granulated sugar" unit="c." qty="0.75 1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="brown sugar" unit="c." qty="3/4 1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="all-purpose flour" unit="c." qty="2" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="baking soda" unit="tsp." qty="1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="shortening" unit="c." qty="1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="peanut butter" unit="c." qty="1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="eggs" unit="" qty="2" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="vanilla extract" unit="tsp." qty="1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<DirS>
<DirT>Drop by spoonful on greased cookie sheet.</DirT>
<DirT>Bake in moderate oven.</DirT>
</DirS>
<!-- NOT SUPPORTED -->
<Desc>Short description, I guess</Desc>
<Srce>krecipes.sourceforge.nte</Srce>
<AltS label="Internet address" source="http://krecipes.sourceforge.net/"/>
<Yield unit="kilogram" qty="1"/>
</RcpE>
<RcpE name="Cookies Test" author="Colleen Beamer">
<Serv qty="2"/><PrpT elapsed="0:30"/>
<CatS>
<CatT>Snacks</CatT>
<CatT>Cookies &amp; Squares</CatT>
</CatS>
<IngR name="granulated sugar" unit="c." qty="0.75 1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="brown sugar" unit="c." qty="3/4 1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="all-purpose flour" unit="c." qty="2" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="baking soda" unit="tsp." qty="1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="shortening" unit="c." qty="1" code="I">
<INtI></INtI>
<IPrp>softened, at room temperature</IPrp>
</IngR>
<IngR name="peanut butter" unit="c." qty="1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="eggs" unit="" qty="2" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<IngR name="vanilla extract" unit="tsp." qty="1" code="I">
<INtI></INtI>
<IPrp></IPrp>
</IngR>
<DirS>
<DirT>Drop by spoonful on greased cookie sheet.</DirT>
<DirT>Bake in moderate oven.</DirT>
</DirS>
<!-- NOT SUPPORTED -->
<Desc>Short description, I guess</Desc>
<Srce>krecipes.sourceforge.nte</Srce>
<AltS label="Internet address" source="http://krecipes.sourceforge.net/"/>
<Yield unit="kilogram" qty="1"/>
</RcpE>
</mx2>

@ -37,39 +37,67 @@ main(int argc, char *argv[])
importer.parseFiles(files);
Recipe recipe;
recipe.title = "Title 1";
recipe.title = "Cookies Test";
recipe.yield.amount = 2;
recipe.yield.type = "servings";
recipe.categoryList.append( Element("Category 1") );
recipe.categoryList.append( Element("Category 2") );
recipe.categoryList.append( Element("Snacks",1) );
recipe.categoryList.append( Element("Cookies & Squares",2) );
recipe.instructions =
"Instruction line 1\n"
"Instruction line 2\n"
"Instruction line 3";
"Drop by spoonful on greased cookie sheet. Bake in moderate oven.\n"
"\n"
"Nutr. Assoc. : 0 1374 1021 927 0 1638 1358 797 0 0 0 568 0 532 1611";
recipe.prepTime = TQTime(0,45);
recipe.authorList.append( Element("Mona Beamer, Colleen Beamer") );
Ingredient ing;
ing.name = "ingredient 1";
ing.amount = 1;
ing.units.name = "teaspoon";
ing.name = "granulated sugar";
ing.amount = 0.75;
ing.units.name = "c.";
recipe.ingList.append( ing );
Ingredient ing2;
ing2.name = "ingredient 2";
ing2.amount = 3.5;
ing2.units.plural = TQString::null;
ing2.name = "brown sugar";
ing2.amount = 1;
ing2.units.name = "c.";
recipe.ingList.append( ing2 );
Ingredient ing3;
ing3.name = "ingredient 3";
ing3.amount = 3.5;
ing3.units.plural = "ounces";
ing3.name = "all-purpose flour";
ing3.amount = 2;
ing3.units.plural = "c.";
recipe.ingList.append( ing3 );
Ingredient ing4;
ing4.name = "ingredient 4";
ing4.amount = 3.5;
ing4.units.plural = "ounces";
ing4.name = "baking soda";
ing4.amount = 1;
ing4.units.name = "tsp.";
recipe.ingList.append( ing4 );
Ingredient ing8;
ing8.name = "shortening";
ing8.amount = 1;
ing8.units.name = "c.";
ing8.prepMethodList.append( Element("softened,at room temperature") );
recipe.ingList.append( ing8 );
Ingredient ing6;
ing6.name = "peanut butter";
ing6.amount = 1;
ing6.units.name = "c.";
recipe.ingList.append( ing6 );
Ingredient ing5;
ing5.name = "eggs";
ing5.amount = 2;
ing5.units.plural = "";
recipe.ingList.append( ing5 );
Ingredient ing7;
ing7.name = "vanilla extract";
ing7.amount = 1;
ing7.units.name = "tsp.";
recipe.ingList.append( ing7 );
check( importer, recipe );

@ -1,4 +1,4 @@
----- Exported by Krecipes vSVN_PRE-0.9 [Master Cook Export Format] -----
* Exported from MasterCook *
Cookies Test
@ -12,11 +12,38 @@ Categories : Snacks Cookies & Squares
3/4 c. granulated sugar
1 c. brown sugar
2 c. all-purpose flour
1 tsp. baking soda
1 c. shortening -- softened,at room temperature
1 c. peanut butter
1 tsp. baking soda
1 c. shortening -- softened,at room temperature
1 c. peanut butter
2 eggs
1 tsp. vanilla extract
1 tsp. vanilla extract
Drop by spoonful on greased cookie sheet. Bake in moderate oven.
Nutr. Assoc. : 0 1374 1021 927 0 1638 1358 797 0 0 0 568 0 532 1611
- - - -
* Exported from MasterCook *
Cookies Test
Recipe By : Mona Beamer, Colleen Beamer
Serving Size : 2 Preparation Time :0:45
Categories : Snacks Cookies & Squares
Amount Measure Ingredient -- Preparation Method
-------- ------------ --------------------------------
3/4 c. granulated sugar
1 c. brown sugar
2 c. all-purpose flour
1 tsp. baking soda
1 c. shortening -- softened,at room temperature
1 c. peanut butter
2 eggs
1 tsp. vanilla extract
Drop by spoonful on greased cookie sheet. Bake in moderate oven.

@ -144,16 +144,16 @@ main(int argc, char *argv[])
printf("Creating RecipeMLExporter.\n");
RecipeMLExporter exporter("not needed",".mmf");
check( exporter, recipeList );
printf("Successfully exported recipes to test.txt.\n");
const char *outfile = "recipemltest_output.txt";
check( outfile , exporter, recipeList );
printf("Successfully exported recipes to %s.\n", outfile);
printf("Creating RecipeMLImporter to test exported recipes.\n");
RecipeMLImporter importer2;
printf("Parsing test.txt.\n");
TQStringList files2; files2 << "test.txt";
printf("Parsing %s.\n", outfile);
TQStringList files2; files2 << TQString(outfile);
importer2.parseFiles(files2);
TQFile::remove("test.txt");
check( importer2, recipe );
printf("Recipe export successful.\n");

@ -46,7 +46,7 @@ main(int argc, char *argv[])
recipe.categoryList.append( Element("Snacks") );
recipe.categoryList.append( Element("Cookies & Squares") );
recipe.instructions =
"\n\nDrop by spoonful on greased cookie sheet. Bake in moderate oven.";
"Drop by spoonful on greased cookie sheet. Bake in moderate oven.";
recipe.authorList.append( Element("Mona Beamer") );
recipe.authorList.append( Element("Colleen Beamer") );
@ -143,16 +143,53 @@ main(int argc, char *argv[])
printf("Creating RezkonvExporter.\n");
RezkonvExporter exporter("not needed",".rk");
check( exporter, recipeList );
printf("Successfully exported recipes to test.txt.\n");
const char *outfile = "rezkonvtest_output.txt";
check( outfile , exporter, recipeList );
printf("Successfully exported recipes to %s.\n", outfile);
printf("Creating RezkonvImporter to test exported recipes.\n");
RezkonvImporter importer2;
printf("Parsing test.txt.\n");
TQStringList files2; files2 << "test.txt";
printf("Parsing %s.\n", outfile);
TQStringList files2; files2 << TQString(outfile);
importer2.parseFiles(files2);
TQFile::remove("test.txt");
//We need to change some strings from english to german because rezkonv
//export format is supposed to provide unit names in german.
recipe.ingList.clear();
ing9.substitutes.clear();
ing9.units.name = "Tassen";
ing9_1.units.plural = "Tasse";
ing9_2.units.plural = "Tasse";
ing9.substitutes.append(ing9_1);
ing9.substitutes.append(ing9_2);
recipe.ingList.append( ing9 );
ing.units.name = "Tassen";
recipe.ingList.append( ing );
ing2.units.name = "Tassen";
recipe.ingList.append( ing2 );
ing3.units.plural = "Tasse";
recipe.ingList.append( ing3 );
ing4.units.name = "Teel.";
recipe.ingList.append( ing4 );
ing8.units.name = "Tassen";
recipe.ingList.append( ing8 );
ing6.units.name = "Tassen";
recipe.ingList.append( ing6 );
recipe.ingList.append( ing5 );
ing7.units.name = "Teel.";
recipe.ingList.append( ing7 );
check( importer2, recipe );
printf("Recipe export successful.\n");

Loading…
Cancel
Save