summaryrefslogtreecommitdiff
path: root/qa/qt/qmc_source/qmc_source.cpp
blob: ea753f7e1a1c9a56fd2f5a6a52d939e445adf05b (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
//
// Test QmcSource class
//

#include <QTextStream>
#include <qmc_source.h>

QTextStream cerr(stderr);
QTextStream cout(stdout);

int
main(int argc, char* argv[])
{
    int		sts = 0;
    int		c;
    char	buf[MAXHOSTNAMELEN];
    QString	source;

    pmProgname = basename(argv[0]);

    while ((c = getopt(argc, argv, "D:?")) != EOF) {
	switch (c) {
	case 'D':
	    sts = __pmParseDebug(optarg);
            if (sts < 0) {
		pmprintf("%s: unrecognized debug flag specification (%s)\n",
			 pmProgname, optarg);
                sts = 1;
            }
            else {
                pmDebug |= sts;
		sts = 0;
	    }
            break;
	case '?':
	default:
	    sts = 1;
	    break;
	}
    }

    if (sts) {
	pmprintf("Usage: %s\n", pmProgname);
	pmflush();
	exit(1);
        /*NOTREACHED*/
    }

    (void)gethostname(buf, MAXHOSTNAMELEN);
    buf[MAXHOSTNAMELEN-1] = '\0';

    fprintf(stderr,"*** Create an archive context ***\n");
    source = "archives/oview-short";
    QmcSource* src1 = QmcSource::getSource(PM_CONTEXT_ARCHIVE, source, false);

    if (src1->status() < 0) {
	pmprintf("%s: Error: Unable to create context to \"oview-short\": %s\n",
		 pmProgname, pmErrStr(src1->status()));
	pmflush();
	sts = 1;
    }

    fprintf(stderr,"\n*** Create an archive context using the host name ***\n");
    source = QString("snort");
    QmcSource* src2 = QmcSource::getSource(PM_CONTEXT_HOST, source, true);

    if (src2->status() < 0) {
	pmprintf("%s: Error: Unable to create context to \"%s\": %s\n",
		pmProgname, (const char *)source.toAscii(),
		pmErrStr(src2->status()));
	pmflush();
	sts = 1;
    }

    if (src1 != src2) {
	pmprintf("%s: Error: Matching host to an archive failed: src1 = %s, src2 = %s\n",
		 pmProgname, (const char *)src1->desc().toAscii(),
		(const char *)src2->desc().toAscii());
	pmflush();
	QmcSource::dumpList(cerr);
	sts = 1;
    }

    fprintf(stderr,"\n*** Create two live contexts to the local host ***\n");
    source = buf;
    QmcSource* src3 = QmcSource::getSource(PM_CONTEXT_HOST, source);
    QmcSource* src4 = QmcSource::getSource(PM_CONTEXT_HOST, source);

    if (src3->status() < 0) {
	pmprintf("%s: Error: Unable to create context to \"%s\": %s\n",
		 pmProgname, buf, pmErrStr(src3->status()));
	pmflush();
    }

    if (src4->status() < 0) {
	pmprintf("%s: Error: Unable to create context to \"%s\": %s\n",
		 pmProgname, buf, pmErrStr(src4->status()));
	pmflush();
    }

    if (src3 != src4) {
	pmprintf("%s: Error: Identical host test failed: src3 = %s, src4 = %s\n",
		 pmProgname, (const char *)src3->desc().toAscii(),
		(const char *)src4->desc().toAscii());
	pmflush();
	QmcSource::dumpList(cerr);
	sts = 1;
    }

    fprintf(stderr,"\n*** Create a local context ***\n");
    source = QString::null;
    QmcSource* src5 = QmcSource::getSource(PM_CONTEXT_LOCAL, source);
    
    if (src5->status() < 0) {
	pmprintf("%s: Error: Unable to create context to localhost: %s\n",
		 pmProgname, pmErrStr(src5->status()));
	pmflush();
	sts = 1;
    }

    fprintf(stderr,"\n*** List all known sources ***\n");
    QmcSource::dumpList(cout);

    pmflush();
    return sts;
}