2
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.carbide.cpp.codescanner.tests;
|
|
19 |
|
|
20 |
import junit.framework.TestCase;
|
|
21 |
|
|
22 |
import com.nokia.carbide.cpp.internal.codescanner.config.CSCategory;
|
|
23 |
import com.nokia.carbide.cpp.internal.codescanner.config.CSRule;
|
|
24 |
import com.nokia.carbide.cpp.internal.codescanner.config.CSScript;
|
|
25 |
import com.nokia.carbide.cpp.internal.codescanner.config.CSSeverity;
|
|
26 |
import com.nokia.carbide.cpp.internal.codescanner.ui.CSRulesSorter;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Test cases for Class CSRulesSorter.
|
|
30 |
*
|
|
31 |
*/
|
|
32 |
public class CSRulesSorterTest extends TestCase {
|
|
33 |
|
|
34 |
private static CSRulesSorter rulesSorter;
|
|
35 |
|
|
36 |
protected void setUp() throws Exception {
|
|
37 |
super.setUp();
|
|
38 |
if (rulesSorter == null) {
|
|
39 |
rulesSorter = new CSRulesSorter();
|
|
40 |
}
|
|
41 |
}
|
|
42 |
|
|
43 |
protected void tearDown() throws Exception {
|
|
44 |
super.tearDown();
|
|
45 |
}
|
|
46 |
|
|
47 |
public void testSetSortingType() {
|
|
48 |
rulesSorter.setSortingType(CSRulesSorter.SORT_BY_CATEGORY);
|
|
49 |
assertEquals(CSRulesSorter.SORT_BY_CATEGORY, rulesSorter.getSortingType());
|
|
50 |
rulesSorter.setSortingType(CSRulesSorter.SORT_BY_RULE);
|
|
51 |
assertEquals(CSRulesSorter.SORT_BY_RULE, rulesSorter.getSortingType());
|
|
52 |
rulesSorter.setSortingType(CSRulesSorter.SORT_BY_SEVERITY);
|
|
53 |
assertEquals(CSRulesSorter.SORT_BY_SEVERITY, rulesSorter.getSortingType());
|
|
54 |
rulesSorter.setSortingType(-1);
|
|
55 |
assertEquals(CSRulesSorter.SORT_BY_RULE, rulesSorter.getSortingType());
|
|
56 |
rulesSorter.setSortingType(100);
|
|
57 |
assertEquals(CSRulesSorter.SORT_BY_RULE, rulesSorter.getSortingType());
|
|
58 |
}
|
|
59 |
|
|
60 |
public void testCompareViewerObjectObject() {
|
|
61 |
CSRule rule1 = new CSRule(CSScript.script_accessArrayElementWithoutCheck,
|
|
62 |
CSCategory.category_codereview,
|
|
63 |
CSSeverity.severity_low,
|
|
64 |
true);
|
|
65 |
CSRule rule2 = new CSRule(CSScript.script_accessArrayElementWithoutCheck,
|
|
66 |
CSCategory.category_codingstandards,
|
|
67 |
CSSeverity.severity_medium,
|
|
68 |
true);
|
|
69 |
CSRule rule3 = new CSRule(CSScript.script_activestart,
|
|
70 |
CSCategory.category_codereview,
|
|
71 |
CSSeverity.severity_medium,
|
|
72 |
true);
|
|
73 |
rulesSorter.setSortingType(CSRulesSorter.SORT_BY_CATEGORY);
|
|
74 |
assertTrue(rulesSorter.compare(null, rule1, rule2) == -1);
|
|
75 |
assertTrue(rulesSorter.compare(null, rule1, rule3) == 0);
|
|
76 |
assertTrue(rulesSorter.compare(null, rule2, rule3) == 1);
|
|
77 |
rulesSorter.setSortingType(CSRulesSorter.SORT_BY_RULE);
|
|
78 |
assertTrue(rulesSorter.compare(null, rule1, rule3) == -1);
|
|
79 |
assertTrue(rulesSorter.compare(null, rule1, rule2) == 0);
|
|
80 |
assertTrue(rulesSorter.compare(null, rule3, rule2) == 1);
|
|
81 |
rulesSorter.setSortingType(CSRulesSorter.SORT_BY_SEVERITY);
|
|
82 |
assertTrue(rulesSorter.compare(null, rule2, rule1) == -1);
|
|
83 |
assertTrue(rulesSorter.compare(null, rule2, rule3) == 0);
|
|
84 |
assertTrue(rulesSorter.compare(null, rule1, rule3) == 1);
|
|
85 |
}
|
|
86 |
|
|
87 |
}
|