1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *     Red Hat Inc. - Bug 462631
11  * Port to the D Programming Language:
12  *     alice <stigma@disroot.org>
13  *******************************************************************************/
14 module tests.SWTException;
15 
16 import java.io.ByteArrayOutputStream;
17 import java.io.PrintStream;
18 import java.lang.all;
19 
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.SWTException;
22 
23 /**
24  * Automated Test Suite for class org.eclipse.swt.SWTException
25  *
26  * @see org.eclipse.swt.SWTException
27  */
28 
29 @("test_Constructor")
30 unittest
31 {
32     assert(
33         new SWTException().code == SWT.ERROR_UNSPECIFIED,
34         "did not fill in code properly");
35 }
36 
37 @("test_ConstructorI")
38 unittest
39 {
40     assert(
41         new SWTException(SWT.ERROR_CANNOT_BE_ZERO).code == SWT.ERROR_CANNOT_BE_ZERO,
42         "did not fill in code properly");
43 }
44 
45 @("test_ConstructorILjava_lang_String")
46 unittest
47 {
48     assert(
49         new SWTException(SWT.ERROR_CANNOT_BE_ZERO, "An uninteresting message").code ==
50             SWT.ERROR_CANNOT_BE_ZERO,
51         "did not fill in code properly"
52     );
53 }
54 
55 @("test_ConstructorLjava_lang_String")
56 unittest
57 {
58     assert(
59         new SWTException("An uninteresting message").code == SWT.ERROR_UNSPECIFIED,
60         "did not fill in code properly"
61     );
62 }
63 
64 @("test_getMessage")
65 unittest
66 {
67     assert(
68         new SWTException(SWT.ERROR_CANNOT_BE_ZERO, "An uninteresting message").getMessage()
69             .indexOf("An uninteresting message") >= 0,
70         "did not include creation string in result"
71     );
72 }
73 
74 @("test_printStackTrace")
75 unittest
76 {
77 
78     // WARNING: this test is not CLDC safe, because it requires java.io.PrintStream
79 
80     if (ClassInfo.find("java.io.PrintStream.PrintStream") is null) {
81         // ignore test if running on CLDC
82         return;
83     }
84 
85     /*
86     DWT: The following tests are commented out since there are a few things missing:
87      * System.setErr
88      * All PrintStream.__ctor() overloads are "implMissing"
89      * SWTException.printStackTrace not using System.err
90      * new_String(byte[])
91 
92     // test default SWTException
93 
94     ByteArrayOutputStream out_ = new ByteArrayOutputStream();
95     System.setErr(new PrintStream(out_));
96     SWTException error = new SWTException();
97     error.printStackTrace();
98     assert(out_.size() > 0);
99     assert(new_String(out_.toByteArray()).indexOf("test_printStackTrace") != -1);
100 
101 
102     // test SWTException with code
103 
104     out_ = new ByteArrayOutputStream();
105     System.setErr(new PrintStream(out_));
106     error = new SWTException(SWT.ERROR_INVALID_ARGUMENT);
107     error.printStackTrace();
108     assert(out_.size() > 0);
109     assert(new_String(out_.toByteArray()).indexOf("test_printStackTrace") != -1);
110     */
111 }