teste.cpp
7.17 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/***************************************************************************
* Copyright (C) 2005 by Jeff Ferr *
* root@sat *
* *
* 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. *
* *
* 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "jsystem.h"
#include "jurl.h"
#include "jdate.h"
#include "jproperties.h"
#include "jxmlparser.h"
#include "jhtmlparser.h"
#include "jstringutils.h"
#include "jstringtokenizer.h"
#include "jdynamiclink.h"
#include "joptions.h"
#include "jfile.h"
#include <iostream>
namespace teste {
class Teste : public jcommon::Object{
public:
Teste():jcommon::Object()
{
jcommon::Object::SetClassName("teste::Teste");
std::cout << "Hello, world !" << std::cout;
}
};
}
void testObject()
{
std::cout << "\n\nTesting Object ...\n" << std::endl;
teste::Teste t;
std::cout << t.what() << std::endl;
if (t.InstanceOf("jcommon::Object") == true) {
std::cout << "Teste is instance of Object" << std::endl;
} else {
std::cout << "Teste is not instance of Object" << std::endl;
}
}
void testTrim()
{
std::string text = " Testando a chamada de funcao Trim\t\t\t\t ";
text = jcommon::StringUtils::Trim(text);
std::cout << ":: Trim :: [" << text << "]" << std::endl << std::endl;
}
void testLink()
{
jcommon::DynamicLink link;
double (**cossine)(double) = NULL;
link.Load("libm.so", jcommon::JLF_LAZY);
*(void **)(cossine) = link.FindSymbol("cos");
std::cout << "Cos(0.0) = " << (*cossine)(0.0) << std::endl;
link.Unload();
}
void testProperties()
{
jcommon::Properties p;
p.Load("/var/dlive/config/reflector.ini");
p.Save();
}
void testSystem()
{
jcommon::System::EnableKeyboardBuffer(false);
jcommon::System::Getch();
jcommon::System::EnableKeyboardBuffer(true);
jcommon::System::Getch();
}
void testStringToken()
{
std::string s = "O Playstation 3 eh o melhor video-game da atualidade.\nNele podemos encontrar os recursos mais avancados de memoria e processamento suficientes para executar os melhores e mais avancados jogos.\n\t\tMesmo assim, eu gostaria de ter um Wii aqui para a nossa empresa, desta maneira todos nos poderiamos dispersar a tensao apenas com alguns minutos de diversao interativa de qualidade. O XBox naum presta, eu soh estou citando ele para encher linguica e conseguir observar a justificacao do texto";
jcommon::StringTokenizer t(s, "\n", jcommon::JTT_STRING, false);
std::vector<std::string> super_lines,
lines,
texts;
std::string temp,
previous;
int max = 100,
word_size;
for (int i=0; i<t.GetSize(); i++) {
temp = jcommon::StringUtils::ReplaceString(t.GetToken(i) + "\n", "\t", " ");
super_lines.push_back(temp);
}
for (int i=0; i<(int)super_lines.size(); i++) {
jcommon::StringTokenizer w(super_lines[i], " ", jcommon::JTT_STRING, true);
std::vector<std::string> words;
for (int i=0; i<w.GetSize(); i++) {
words.push_back(w.GetToken(i));
}
temp = words[0];
for (int j=1; j<(int)words.size(); j++) {
previous = temp;
temp += words[j];
// font->GetStringWidth(font, temp.c_str(), -1, &word_size);
word_size = temp.size();
if (word_size > (max + 1)) {
temp = words[j];
texts.push_back(previous);
}
}
texts.push_back(temp);
}
for (int i=0; i<(int)texts.size(); i++) {
std::cout << texts[i] << std::endl;
}
}
void testURL()
{
jcommon::URL *url[] = {
new jcommon::URL("http://www.google.com/url/http://redirect.org"),
new jcommon::URL("http://www.google.com/?url=http://redirect.org"),
new jcommon::URL("http://charges.com/a?a=1"),
new jcommon::URL("ftp://www.lavid.ufpb.br/cvs#ref"),
new jcommon::URL("http://phrack.com:80/?a=1&b=2"),
new jcommon::URL("http://phrack.com:80"),
new jcommon::URL("file:///test/file.mpg"),
new jcommon::URL("file://test/file.mpg"),
new jcommon::URL("./file.mpg"),
new jcommon::URL("/file.mpg"),
new jcommon::URL("file.mpg"),
new jcommon::URL("file:/file.mpg")
};
for (int i=0; i<12; i++) {
std::cout << "-------------------------------" << std::endl;
std::cout << "URL: [" << url[i]->what() << "]" << std::endl;
std::cout << "GetProtocol(): " << url[i]->GetProtocol() << std::endl;
if (url[i]->GetProtocol() == "file") {
std::cout << "GetPath(): " << jio::File::NormalizePath(url[i]->GetPath()) << std::endl;
} else {
std::cout << "GetPath(): " << url[i]->GetPath() << std::endl;
}
std::cout << "GetQuery(): " << url[i]->GetQuery() << std::endl;
std::cout << "GetHost(): " << url[i]->GetHost() << std::endl;
std::cout << "GetPort(): " << url[i]->GetPort() << std::endl;
std::cout << "GetFile(): " << url[i]->GetFile() << std::endl;
std::cout << "GetParameters(): " << url[i]->GetParameters() << std::endl;
std::cout << "GetReference(): " << url[i]->GetReference() << std::endl;
delete url[i];
}
}
void testOptions(int argc, char **argv)
{
jcommon::Options o(argc, argv);
o.SetOptions("a:");
std::cout << "Options:: " << o.ExistsOption("a") << ", " << o.ExistsOption("b") << ", " << o.GetArgument("a") << ", " << o.GetArgument("b") << std::endl;
}
void testDate()
{
long long t = jcommon::Date::CurrentTimeMillis();
t = t/1000LL;
jcommon::Date d((time_t)t);
std::cout << "Date:: " << d.what() << std::endl;
}
void create_xml_file()
{
jcommon::XmlDocument doc;
jcommon::XmlElement *component = new jcommon::XmlElement("component");
component->SetAttribute("alias", "1");
component->SetAttribute("guid", "2");
doc.LinkEndChild(component);
doc.SaveFile("j.xml");
}
void html_parser_test()
{
jcommon::HTMLParser parser;
parser.Parse("./index.html");
parser.Dump();
}
int main(int argc, char *argv[])
{
//testObject();
testTrim();
//testLink();
//testProperties();
//testSystem();
//testStringToken();
testURL();
//testOptions(argc, argv);
//testDate();
//create_xml_file();
//html_parser_test();
return EXIT_SUCCESS;
}