File: Params.cpp

package info (click to toggle)
xalan 1.12-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,368 kB
  • sloc: cpp: 145,645; xml: 1,523; ansic: 434; sh: 27; makefile: 17
file content (318 lines) | stat: -rw-r--r-- 10,414 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the  "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// Base header file.  Must be first.
#include <xalanc/Include/PlatformDefinitions.hpp>



#include <cstdio>

#include <iostream>

// This is here for memory leak testing. 
#if !defined(NDEBUG) && defined(_MSC_VER)
#include <crtdbg.h>
#endif



#include <xercesc/util/PlatformUtils.hpp>



#include <xalanc/PlatformSupport/XalanUnicode.hpp>



#include <xalanc/XSLT/XSLTInputSource.hpp>
#include <xalanc/XSLT/XSLTResultTarget.hpp>



#include <xalanc/XalanTransformer/XalanTransformer.hpp>



#include <xalanc/Harness/XalanXMLFileReporter.hpp>
#include <xalanc/Harness/XalanFileUtility.hpp>



using std::cerr;
using std::cout;
using std::endl;



using xalanc::XalanFileUtility;
using xalanc::XalanDOMString;



void
setHelp(XalanFileUtility&   h)
{
    h.args.getHelpStream() << endl
         << "params dirname [-out]"
         << endl
         << endl
         << "dirname        (base directory for \'capi\' testcases)"
         << endl
         << "-out dirname   (base directory for output)"
         << endl;
}



//  This function returns the testcase number.  All of these tests are called
//  params0X, and there are only 6 of them,  so we can pick off the
//  second X to determine what test number we're dealing with.  We need to
//  know which test because each test gets different parameters. This code will
//  need modification if the number of tests changes.
int
getTestNumber(const XalanDOMString&     theFile)
{
    assert(8 < theFile.length());

    return theFile[7] - xalanc::XalanUnicode::charDigit_0;
}



int
runTests(
            int     argc,
            char*   argv[])
{
    int             theResult = 0;

    XalanFileUtility    h;

    char testCase[15];
    XalanDOMString fileName, theGoldFile;
    const XalanDOMString  currentDir("params");

    // Set the program help string,  then get the command line parameters.
    //
    setHelp(h);

    // Get the command line parameters.
    //
    if (h.getParams(argc, argv, "PARAMS-RESULTS") == true)
    {
        const XalanDOMString    extDir(h.args.base + currentDir);

        // Check that the base directory is correct.
        if ( !h.checkDir(extDir) )
        {
            cout << "Invalid base directory - " << extDir << endl;
            cout << h.args.getHelpMessage();

            theResult = -1;
        }
        else
        {
            using xalanc::XalanTransformer;
            using xalanc::XalanXMLFileReporter;

            XalanTransformer    xalan;

            // Generate Unique Run id. (Only used to name the result logfile.)
            const XalanDOMString    UniqRunid = h.generateUniqRunid();

            // Defined basic constants for file manipulation
            const XalanDOMString    drive(h.getDrive());
            const XalanDOMString    resultFilePrefix("params");
            const XalanDOMString    resultsFile(drive + h.args.output + resultFilePrefix + UniqRunid + XalanFileUtility::s_xmlSuffix);
            
            XalanXMLFileReporter        logFile(resultsFile);

            logFile.logTestFileInit("Param Testing: Testing ability to pass parameters to stylesheets. ");

            try
            {
                bool embedFlag =  false;
                    
                // Get the files found in the "params" directory
                const XalanDOMString  theOutputDir = h.args.output + currentDir;

                // Check that output directory is there.
                h.checkAndCreateDir(theOutputDir);

                typedef XalanFileUtility::FileNameVectorType        FileNameVectorType;

                const FileNameVectorType    files = h.getTestFileNames(h.args.base, currentDir, true);
                logFile.logTestCaseInit(currentDir);

                for(FileNameVectorType::size_type i = 0; i < files.size(); ++i)
                {
                    fileName = files[i];
                    sprintf(testCase, "%s%d","TestCase",i+1);
                    h.data.testOrFile = testCase;

                    // Set up the input/output files.
                    const XalanDOMString  theXSLFile= h.args.base + currentDir + XalanFileUtility::s_pathSep + fileName;
                    XalanDOMString        theXMLFile;
                    
                    // Neither testcase 7 nor 8 utilize xml source files. Both use fragment identifiers,
                    // so the generation of xml file is unnecessary.
                    // Testcase 7 tests: <?xml-stylesheet type="text/xsl" href="#style1-23.34.123456789_345"?>
                    // Testcase 8 tests: <?xml-stylesheet type="text/xsl" href="foo.xsl"?>
                    if ( i+1 <= 6 )
                    {
                        theXMLFile = h.generateFileName(theXSLFile, "xml");
                    }

                    h.data.xmlFileURL = theXMLFile;
                    h.data.xslFileURL = theXSLFile;

                    const XalanDOMString  theOutput =  h.args.output + currentDir + XalanFileUtility::s_pathSep + fileName; 
                    const XalanDOMString  theOutputFile = h.generateFileName(theOutput, "out");
                    theGoldFile = h.args.gold + currentDir + XalanFileUtility::s_pathSep + fileName;
                    theGoldFile = h.generateFileName(theGoldFile, "out");

                    using xalanc::XSLTResultTarget;;
                    using xalanc::XSLTInputSource;;

                    const XSLTResultTarget  theResultTarget(theOutputFile);
                    const XSLTInputSource   xslInputSource(theXSLFile);
                    const XSLTInputSource   xmlInputSource(theXMLFile);
                            
                    // Set the desired parameters
                    switch (getTestNumber(fileName))
                    {   
                        case 2:
                            xalan.setStylesheetParam("in1", "'A '");

                            xalan.setStylesheetParam("in2", "'B '");

                            xalan.setStylesheetParam(
                                XalanDOMString("in3"),
                                XalanDOMString("'C '"));
                            xalan.setStylesheetParam(
                                XalanDOMString("in4"),
                                XalanDOMString("'D '"));
                            xalan.setStylesheetParam(
                                XalanDOMString("in5"),
                                XalanDOMString("'E '"));
                            break;

                        case 3:
                            xalan.setStylesheetParam(
                                XalanDOMString("'xyz:in1'"),
                                XalanDOMString("'DATA'"));
                            break;

                        case 7:
                            {
                                const XSLTInputSource   embed07InputSource(theXSLFile);
                                xalan.transform(embed07InputSource, theResultTarget);
                                h.data.testOrFile += " (Embed01)";
                                embedFlag = true;
                                break;
                            }

                        case 8:
                            {
                                const XSLTInputSource   embed08InputSource(theXSLFile);
                                xalan.transform(embed08InputSource, theResultTarget);
                                h.data.testOrFile += " (Embed02)";
                                embedFlag = true;
                                break;
                            }
                        default:
                            xalan.setStylesheetParam(
                                XalanDOMString("input"),
                                XalanDOMString("'testing 1 2 3'"));
                            break;
                    }

                    // Do a total end to end transform with no pre parsing of either xsl or xml files.
                    if (!embedFlag)
                    {
                        xalan.transform(xmlInputSource, xslInputSource, theResultTarget);
                    }

                    // Check and report the results.
                    h.checkResults(theOutputFile, theGoldFile, logFile);
                }
                                
                logFile.logTestCaseClose("Done", "Pass");
            }
            catch(...)
            {
                cerr << "Exception caught!!!" << endl << endl;

                theResult = -1;
            }

            h.reportPassFail(logFile, UniqRunid);
            logFile.logTestFileClose("Param Testing: ", "Done");
            logFile.close();

            h.analyzeResults(xalan, resultsFile);
        }
    }

    return theResult;
}



int
main(
            int     argc,
            char*   argv[])
{
#if !defined(NDEBUG) && defined(_MSC_VER)
    _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif

    int theResult = 0;

    try
    {
        using xercesc::XMLPlatformUtils;

        using xalanc::XalanTransformer;

        // Call the static initializers for xerces and xalan, and create a transformer
        //
        XMLPlatformUtils::Initialize();

        XalanTransformer::initialize();

        theResult = runTests(argc, argv);

        XalanTransformer::terminate();

        XMLPlatformUtils::Terminate();

        XalanTransformer::ICUCleanUp();
    }
    catch(...)
    {
        cerr << "Initialization failed!" << endl << endl;

        theResult = -1;
    }

    return theResult;
}