File: notQttest.cpp

package info (click to toggle)
nxcl 0.9-3.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 560 kB
  • ctags: 412
  • sloc: cpp: 3,149; makefile: 114
file content (147 lines) | stat: -rw-r--r-- 4,367 bytes parent folder | download | duplicates (4)
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
/***************************************************************************
   notQttest.cpp - A test of some of the features in ../lib/notQt.cpp
                             -------------------
    begin                : June 2007
    copyright            : (C) 2007 Embedded Software Foundry Ltd. (U.K.)
                         :     Author: Sebastian James
    email                : seb@esfnet.co.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <iostream>
#include <string>
#include <list>

#include "notQt.h"

using namespace std;
using namespace nxcl;

ofstream debugLogFile;

notQProcess p2;

void processParseStdout()
{
	string message = p2.readAllStandardOutput();
	cout << "processParseStdout called, message is: " << message << endl;
}
void processParseStderr()
{
	string message = p2.readAllStandardError();	
	cout << "processParseStderr called, message is: " << message << endl;
}

int main()
{

	debugLogFile.open("/tmp/notQttest.log", ios::out|ios::trunc);

	// Test temporary files
	notQTemporaryFile tf;
	tf.open();
	tf.write ("this is a temporary file, jim");
	cout << "tmp filename is " << tf.fileName() << endl;
	tf.close();

	// Test utilities
	string tstring = "\n\n  this \t  is\n a\t\t   test string    ";
	cout << "test string is '" << tstring << "'" << endl;
	cout << "simplify returns '" << notQtUtilities::simplify (tstring) << "'" << endl;

        tstring = "Nowhitespaceatall";
	cout << "test string is '" << tstring << "'" << endl;
	cout << "simplify returns '" << notQtUtilities::simplify (tstring) << "'" << endl;

	tstring = "one two three\tfour";
	vector<string> v;
	notQtUtilities::splitString (tstring, ' ', v);
	cout << "v.size() = " << v.size() << endl;
	for (unsigned int i=0; i<v.size(); i++) {
		cout << "v["<<i<<"]='" << v[i] << "'" << endl;
	}
	/*
	vector<string> v2;
	notQtUtilities::splitString (tstring, 'h', v2);
	cout << "v2.size() = " << v2.size() << endl;
	for (unsigned int i=0; i<v2.size(); i++) {
		cout << "v2["<<i<<"]='" << v2[i] << "'" << endl;
	}
	*/

	// Test processes to read some input
	notQProcess p;
	string program = "/usr/bin/tee";
	list<string> args;       
	// Always push_back the program first.
	args.push_back(program);
	args.push_back("teeout");
	p.start (program, args);
	cout << "p.getPid=" << p.getPid() << endl;
	if (p.waitForStarted() == true) {
		string data = "Some input text";
		p.writeIn (data);

	} else { 
		cout << "not started" << endl;
		return -1;
	}

	// Test process that generates output
	bool finished = false;
//	program = "/usr/bin/eo";
	program = "/usr/bin/tee";
	args.clear();
	// Always push_back the program first.
	args.push_back(program);
	args.push_back("hello");

	// p2 is a global in this test

/* FIXME: This needs to be changed, now that we got rid of boost signals.
	p2.readyReadStandardOutputSignal.connect (&processParseStdout);
	p2.readyReadStandardErrorSignal.connect (&processParseStderr);
*/
	p2.start (program, args);
	cout << "p2.getPid=" << p2.getPid() << endl;
	if (p2.waitForStarted() == true) {
		string output;
		string errout;
		string instring = "data, data";
		while (finished == false) {
			p2.probeProcess();
/* You can get the output without signals:
			output = p2.readAllStandardOutput();
			errout = p2.readAllStandardError();
			if (output.size()>0) {
				cout << program << " generated this output: " << output << endl;
				finished = true;
			}
			if (errout.size()>0) {
				cout << program << " generated this error: " << errout << endl;
				finished = true;
			}
			cout << "sleeping" << endl;
*/	
			usleep (1000000);
			p2.writeIn (instring);
			usleep (1000000);
		}

	} else { 
		cout << "not started" << endl;
		return -1;
	}

	debugLogFile.close();

	return 0;
}