File: InterviewSaveTest.java

package info (click to toggle)
jtharness 6.0-b24-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, trixie
  • size: 17,364 kB
  • sloc: java: 163,504; xml: 3,489; haskell: 250; makefile: 7
file content (92 lines) | stat: -rw-r--r-- 3,059 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
/*
 * $Id$
 *
 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code 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
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package com.sun.interview;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

import com.sun.javatest.TestUtil;
import com.sun.javatest.TestSuite;
import org.junit.Assert;
import org.junit.Test;

public class InterviewSaveTest {

    @Test
    public void test() throws Exception {
        InterviewSaveTest t = new InterviewSaveTest();
        boolean ok = t.run(new String[] {TestUtil.getPathToTestTestSuite("demotck")});
        Assert.assertTrue(ok);
    }

    boolean run(String[] args)
            throws FileNotFoundException, Interview.Fault, TestSuite.Fault {
        TestSuite ts = TestSuite.open(new File(args[0]));
        Interview interview = ts.createInterview();

        Question[] path = interview.getPath();

        boolean ok = true;

        for (int i = 0; i < path.length; i++) {
            interview.setCurrentQuestion(path[i]);

            Map<String, String> m = new HashMap<>();
            interview.save(m);

            Interview int2 = ts.createInterview();
            int2.load(m);

            if (!equal(interview, int2)) {
                System.err.println("test case " + i + ": mismatch");
                ok = false;
            }
        }

        System.err.println(path.length + " test cases ok");
        return ok;
    }

    private boolean equal(Interview i1, Interview i2) {
        return equal(i1.getCurrentQuestion(), i2.getCurrentQuestion());
    }

    private boolean equal(Question q1, Question q2) {
        if (q1 == null || q2 == null)
            return q1 == q2;

        return equal(q1.getKey(), q2.getKey())
                && equal(q1.getStringValue(), q2.getStringValue());
    }

    private boolean equal(String s1, String s2) {
        return s1 == null || s2 == null ? s1 == s2 : s1.equals(s2);
    }
}