summaryrefslogtreecommitdiffstats
path: root/src/tests/rezkonvtest.cpp
blob: 044a90e696834b5f7cf402d5caad07d49fb5a737 (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/***************************************************************************
*   Copyright (C) 2005 by                                                 *
*   Jason Kivlighn (jkivlighn@gmail.com)                                  *
*                                                                         *
*   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 2 of the License, or     *
*   (at your option) any later version.                                   *
***************************************************************************/

#include <tdeaboutdata.h>
#include <tdeapplication.h>
#include <tdecmdlineargs.h>

#include <tqstring.h>

#include <iostream>
using std::cout;
using std::endl;

#include "rezkonvimporter.h"
#include "rezkonvexporter.h"
#include "importertest.h"
#include "exportertest.h"

int
main(int argc, char *argv[])
{
	TDEAboutData *about = new TDEAboutData("rezkonvtest", I18N_NOOP("rezkonvtest"), "1.0",
	        nullptr, TDEAboutData::License_GPL, nullptr, nullptr, nullptr, nullptr);
	TDECmdLineArgs::init(argc, argv, about);
	TDEApplication::disableAutoDcopRegistration(); // will reduce noise when we run without X11
	TDEApplication a(/* allowStyles =*/ false, /* GUIenabled =*/ false);

	printf("Creating RezkonvImporter.\n");
	RezkonvImporter importer;

	printf("Parsing rezkonvtest.txt.\n");
	TQStringList files; files << "rezkonvtest.txt";
	importer.parseFiles(files);

	Recipe recipe;
	recipe.title = "Cookies_Test";
	recipe.yield.amount = 2;
	recipe.yield.amount_offset = 1;
	recipe.yield.type = "dozen";
	recipe.categoryList.append( Element("Snacks") );
	recipe.categoryList.append( Element("Cookies & Squares") );
	recipe.instructions = 
		"Drop by spoonful on greased cookie sheet.  Bake in moderate oven.";

	recipe.authorList.append( Element("Mona Beamer") );
	recipe.authorList.append( Element("Colleen Beamer") );

	Ingredient ing9;
	ing9.name = "a";
	ing9.amount = 1;
	ing9.amount_offset = 0;
	ing9.units.name = "cup";
	IngredientData ing9_1;
	ing9_1.name = "b";
	ing9_1.amount = 2;
	ing9_1.amount_offset = 0;
	ing9_1.units.plural = "cups";
	IngredientData ing9_2;
	ing9_2.name = "c";
	ing9_2.amount = 3;
	ing9_2.amount_offset = 0;
	ing9_2.units.plural = "cups";
	ing9.substitutes.append(ing9_1);
	ing9.substitutes.append(ing9_2);
	recipe.ingList.append( ing9 );

	Ingredient ing;
	ing.name = "granulated sugar";
	ing.amount = 0.75;
	ing.amount_offset = 0.25;
	ing.units.name = "c.";
	ing.groupID = 0; ing.group = "Dry Ingredients";
	recipe.ingList.append( ing );

	Ingredient ing2;
	ing2.name = "brown sugar";
	ing2.amount = 1;
	ing2.amount_offset = 0;
	ing2.units.name = "c.";
	ing2.groupID = 0; ing2.group = "Dry Ingredients";
	recipe.ingList.append( ing2 );

	Ingredient ing3;
	ing3.name = "all-purpose flour";
	ing3.amount = 2;
	ing3.units.plural = "c.";
	ing3.groupID = 0; ing3.group = "Dry Ingredients";
	recipe.ingList.append( ing3 );

	Ingredient ing4;
	ing4.name = "baking soda";
	ing4.amount = 1;
	ing4.amount_offset = 0;
	ing4.units.name = "tsp.";
	ing4.groupID = 0; ing4.group = "Dry Ingredients";
	recipe.ingList.append( ing4 );

	Ingredient ing8;
	ing8.name = "shortening";
	ing8.amount = 1;
	ing8.amount_offset = 0;
	ing8.units.name = "c.";
	ing8.prepMethodList.append( Element("softened") );
	ing8.prepMethodList.append( Element("at room temperature") );
	ing8.groupID = 1; ing8.group = "Fat & Liquids";
	recipe.ingList.append( ing8 );

	Ingredient ing6;
	ing6.name = "peanut butter";
	ing6.amount = 1;
	ing6.amount_offset = 0;
	ing6.units.name = "c.";
	ing6.groupID = 1; ing6.group = "Fat & Liquids";
	recipe.ingList.append( ing6 );

	Ingredient ing5;
	ing5.name = "eggs";
	ing5.amount = 2;
	ing5.amount_offset = 0;
	ing5.units.plural = "";
	ing5.groupID = 1; ing5.group = "Fat & Liquids";
	recipe.ingList.append( ing5 );

	Ingredient ing7;
	ing7.name = "vanilla extract";
	ing7.amount = 1;
	ing7.amount_offset = 0;
	ing7.units.name = "tsp.";
	ing7.groupID = 1; ing7.group = "Fat & Liquids";
	recipe.ingList.append( ing7 );

	check( importer, recipe );

	RecipeList recipeList;
	recipeList.append(recipe);
	recipeList.append(recipe);

	printf("Creating RezkonvExporter.\n");
	RezkonvExporter exporter("not needed",".rk");
	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 %s.\n", outfile);
	TQStringList files2; files2 << TQString(outfile);
	importer2.parseFiles(files2);


	//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");

	printf("Done.\n");
}