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