tracefw/tracecompiler/test/src/GroupNamesTest.java
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
child 22 e26895079d7c
equal deleted inserted replaced
20:ca8a1b6995f6 21:52e343bb8f80
     1 /*
       
     2 * Copyright (c) 2010 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 "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 
       
    19 import static org.junit.Assert.*;
       
    20 import java.io.*;
       
    21 
       
    22 import org.junit.Test;
       
    23 
       
    24 import com.nokia.tracecompiler.TraceCompilerRootException;
       
    25 import com.nokia.tracecompiler.project.*;
       
    26 
       
    27 public class GroupNamesTest { 
       
    28 
       
    29 	
       
    30 	public static void main(String args[]) {		
       
    31 	      	org.junit.runner.JUnitCore.main(GroupNamesTest.class.getName());
       
    32 	    }
       
    33 			
       
    34 	@Test
       
    35 	public void testGetGroupNameVector() {
       
    36 		
       
    37 	
       
    38 		try {
       
    39 			GroupNames.initialiseGroupName();
       
    40 		} catch (TraceCompilerRootException e) {
       
    41 			fail();
       
    42 		}
       
    43 					
       
    44 		// test group id values obtain by name
       
    45 		assertEquals("TRACE_FATAL gid check", GroupNames.getIdByName("TRACE_FATAL"), 129);
       
    46 		assertEquals("TRACE_ERROR gid check", GroupNames.getIdByName("TRACE_ERROR"), 130);
       
    47 		assertEquals("TRACE_WARNING gid check", GroupNames.getIdByName("TRACE_WARNING"), 131);
       
    48 		assertEquals("TRACE_BORDER gid check", GroupNames.getIdByName("TRACE_BORDER"), 132);	    
       
    49 		assertEquals("TRACE_API gid check", GroupNames.getIdByName("TRACE_API"), 132);
       
    50 		assertEquals("TRACE_IMPORTANT gid check", GroupNames.getIdByName("TRACE_IMPORTANT"), 133);
       
    51 		assertEquals("TRACE_NORMAL gid check", GroupNames.getIdByName("TRACE_NORMAL"), 134);
       
    52 		assertEquals("TRACE_STATE gid check", GroupNames.getIdByName("TRACE_STATE"), 135);
       
    53 		assertEquals("TRACE_INTERNALS gid check", GroupNames.getIdByName("TRACE_INTERNALS"), 136);
       
    54 		assertEquals("TRACE_DETAILED", GroupNames.getIdByName("TRACE_DETAILED"), 136);
       
    55 		assertEquals("TRACE_DUMP gid check", GroupNames.getIdByName("TRACE_DUMP"), 137);
       
    56 		assertEquals("TRACE_DEBUG gid check", GroupNames.getIdByName("TRACE_DEBUG"), 137);
       
    57 		assertEquals("TRACE_FLOW gid check", GroupNames.getIdByName("TRACE_FLOW"), 138);
       
    58 		assertEquals("TRACE_PERFORMANCE gid check", GroupNames.getIdByName("TRACE_PERFORMANCE"), 139);
       
    59 		assertEquals("TRACE_ADHOC gid check", GroupNames.getIdByName("TRACE_ADHOC"), 140);
       
    60 		assertEquals("TRACE_EXTENSION gid check", GroupNames.getIdByName("TRACE_EXTENSION"), 141);
       
    61 
       
    62 		// test GID strings obtained by id
       
    63 //		assertEquals("TRACE_FATAL string check", GroupNames.getNameById(129), "TRACE_FATAL");
       
    64 //		assertEquals("TRACE_ERROR string check", GroupNames.getNameById(130), "TRACE_ERROR");
       
    65 //		assertEquals("TRACE_WARNING string check", GroupNames.getNameById(131), "TRACE_WARNING");
       
    66 //		assertEquals("TRACE_BORDER string check", GroupNames.getNameById(132), "TRACE_BORDER");	    
       
    67 //		assertEquals("TRACE_IMPORTANT string check", GroupNames.getNameById(133), "TRACE_IMPORTANT");
       
    68 //		assertEquals("TRACE_NORMAL string check", GroupNames.getNameById(134), "TRACE_NORMAL");
       
    69 //		assertEquals("TRACE_STATE string check", GroupNames.getNameById(135), "TRACE_STATE");
       
    70 //		assertEquals("TRACE_INTERNALS string check", GroupNames.getNameById(136), "TRACE_INTERNALS");
       
    71 //		assertEquals("TRACE_DUMP string check", GroupNames.getNameById(137), "TRACE_DUMP");
       
    72 //		assertEquals("TRACE_FLOW string check", GroupNames.getNameById(138), "TRACE_FLOW");
       
    73 //		assertEquals("TRACE_PERFORMANCE string check", GroupNames.getNameById(139), "TRACE_PERFORMANCE");
       
    74 //		assertEquals("TRACE_ADHOC string check", GroupNames.getNameById(140), "TRACE_ADHOC");
       
    75 //		assertEquals("TRACE_EXTENSION string check", GroupNames.getNameById(141), "TRACE_EXTENSION");	
       
    76 //		assertEquals("TRACE_TESTING1 string check", GroupNames.getNameById(254), "TRACE_TESTING1");
       
    77 //		assertEquals("TRACE_TESTING2 string check", GroupNames.getNameById(255), "TRACE_TESTING2");	
       
    78 	}
       
    79 	
       
    80 	
       
    81 	@Test
       
    82 	public void testUserDefinedRange(){
       
    83 		// test that the user defined range starts at the expected value
       
    84 		assertEquals("user defined range check", GroupNames.USER_GROUP_ID_FIRST, 222);		
       
    85 		assertEquals("user defined range check", GroupNames.USER_GROUP_ID_LAST, 253);
       
    86 			
       
    87 	}
       
    88 	
       
    89 	@Test
       
    90 	public void testModifiedOstHeaderFile(){
       
    91 		// copy a modfified file to epoc32\platform\include, rename ost_types.h, run tests, and then replace original ost_types
       
    92 	    
       
    93 		String e32 = System.getenv("EPOCROOT");
       
    94 		if(e32 == null || (e32.length()==0)){
       
    95 			fail();
       
    96 		}
       
    97 		
       
    98 		// need to check that e32 ends in a backslash
       
    99 		if(!e32.endsWith(File.separator)){ 
       
   100 			e32 += File.separator; 
       
   101 		}
       
   102 		
       
   103 		e32 = e32 + "epoc32"+File.separator+"include"+File.separator+"platform"+File.separator;
       
   104 		
       
   105 		System.out.println(e32);
       
   106 		
       
   107 		System.setProperty("user.dir", e32);
       
   108 		
       
   109 		String curDir = System.getProperty("user.dir");
       
   110 		System.out.println(curDir);
       
   111 		
       
   112 		// File (or directory) with old name
       
   113 	    File file = new File(e32 + "opensystemtrace_types.h");
       
   114 	    
       
   115 	    // File (or directory) with new name
       
   116 	    File file2 = new File(e32 + "CBR_opensystemtrace_types.h");
       
   117 	    
       
   118 	    // File (or directory) with new name
       
   119 	    File file3 = new File(e32 + "test_opensystemtrace_types.h");
       
   120 	    
       
   121 	    // Rename file (or directory)
       
   122 	    boolean success = file.renameTo(file2);
       
   123 	    if (!success) {
       
   124 	        // File was not successfully renamed
       
   125 	    	fail();
       
   126 	    }
       
   127 	    
       
   128 	    // Rename file (or directory)
       
   129 	    success = file3.renameTo(file);
       
   130 	    if (!success) {
       
   131 	        // File was not successfully renamed
       
   132 	    	fail();
       
   133 	    }
       
   134 	    
       
   135 		try {
       
   136 			GroupNames.initialiseGroupName();
       
   137 		} catch (TraceCompilerRootException e) {
       
   138 			fail();
       
   139 		}
       
   140 		
       
   141 		// test group id values obtain by name
       
   142 		assertEquals("TRACE_FATAL gid check", GroupNames.getIdByName("TRACE_FATAL"), 149);
       
   143 		assertEquals("TRACE_ERROR gid check", GroupNames.getIdByName("TRACE_ERROR"), 150);
       
   144 		assertEquals("TRACE_WARNING gid check", GroupNames.getIdByName("TRACE_WARNING"), 151);
       
   145 		assertEquals("TRACE_BORDER gid check", GroupNames.getIdByName("TRACE_BORDER"), 152);	    
       
   146 		assertEquals("TRACE_API gid check", GroupNames.getIdByName("TRACE_API"), 152);
       
   147 		assertEquals("TRACE_IMPORTANT gid check", GroupNames.getIdByName("TRACE_IMPORTANT"), 153);
       
   148 		assertEquals("TRACE_NORMAL gid check", GroupNames.getIdByName("TRACE_NORMAL"), 154);
       
   149 		assertEquals("TRACE_STATE gid check", GroupNames.getIdByName("TRACE_STATE"), 155);
       
   150 		assertEquals("TRACE_INTERNALS gid check", GroupNames.getIdByName("TRACE_INTERNALS"), 156);
       
   151 		assertEquals("TRACE_DETAILED", GroupNames.getIdByName("TRACE_DETAILED"), 156);
       
   152 		assertEquals("TRACE_DUMP gid check", GroupNames.getIdByName("TRACE_DUMP"), 157);
       
   153 		assertEquals("TRACE_DEBUG gid check", GroupNames.getIdByName("TRACE_DEBUG"), 157);
       
   154 		assertEquals("TRACE_FLOW gid check", GroupNames.getIdByName("TRACE_FLOW"), 158);
       
   155 		assertEquals("TRACE_PERFORMANCE gid check", GroupNames.getIdByName("TRACE_PERFORMANCE"), 159);
       
   156 		assertEquals("TRACE_ADHOC gid check", GroupNames.getIdByName("TRACE_ADHOC"), 160);
       
   157 		assertEquals("TRACE_EXTENSION gid check", GroupNames.getIdByName("TRACE_EXTENSION"), 161);
       
   158 
       
   159 		// test GID strings obtained by id
       
   160 //		assertEquals("TRACE_FATAL string check", GroupNames.getNameById(149), "TRACE_FATAL");
       
   161 //		assertEquals("TRACE_ERROR string check", GroupNames.getNameById(150), "TRACE_ERROR");
       
   162 //		assertEquals("TRACE_WARNING string check", GroupNames.getNameById(151), "TRACE_WARNING");
       
   163 //		assertEquals("TRACE_BORDER string check", GroupNames.getNameById(152), "TRACE_BORDER");	    
       
   164 //		assertEquals("TRACE_IMPORTANT string check", GroupNames.getNameById(153), "TRACE_IMPORTANT");
       
   165 //		assertEquals("TRACE_NORMAL string check", GroupNames.getNameById(154), "TRACE_NORMAL");
       
   166 //		assertEquals("TRACE_STATE string check", GroupNames.getNameById(155), "TRACE_STATE");
       
   167 //		assertEquals("TRACE_INTERNALS string check", GroupNames.getNameById(156), "TRACE_INTERNALS");
       
   168 //		assertEquals("TRACE_DUMP string check", GroupNames.getNameById(157), "TRACE_DUMP");
       
   169 //		assertEquals("TRACE_FLOW string check", GroupNames.getNameById(158), "TRACE_FLOW");
       
   170 //		assertEquals("TRACE_PERFORMANCE string check", GroupNames.getNameById(159), "TRACE_PERFORMANCE");
       
   171 //		assertEquals("TRACE_ADHOC string check", GroupNames.getNameById(160), "TRACE_ADHOC");
       
   172 //		assertEquals("TRACE_EXTENSION string check", GroupNames.getNameById(161), "TRACE_EXTENSION");
       
   173 	} 
       
   174    
       
   175 	@Test
       
   176     public void tearDown() {
       
   177         // release objects under test here, if necessary
       
   178 		
       
   179 		String e32 = System.getenv("EPOCROOT");
       
   180 		if(e32 == null || (e32.length()==0)){
       
   181 			fail();
       
   182 		}
       
   183 		
       
   184 		// need to check that e32 ends in a backslash
       
   185 		if(!e32.endsWith(File.separator)){ 
       
   186 			e32 += File.separator; 
       
   187 		}
       
   188 		
       
   189 		e32 = e32 + "epoc32"+File.separator+"include"+File.separator+"platform"+File.separator;
       
   190 		
       
   191 		System.out.println(e32);
       
   192 		
       
   193 		System.setProperty("user.dir", e32);
       
   194 		
       
   195 		String curDir = System.getProperty("user.dir");
       
   196 		System.out.println(curDir);
       
   197 		
       
   198 		// File (or directory) with old name
       
   199 	    File file = new File(e32 + "opensystemtrace_types.h");
       
   200 	    
       
   201 	    // File (or directory) with new name
       
   202 	    File file2 = new File(e32 + "CBR_opensystemtrace_types.h");
       
   203 	    
       
   204 	    	    
       
   205 	    boolean i = file.exists();
       
   206 	    System.out.println(i);
       
   207 	    
       
   208 	    // Rename file (or directory)
       
   209 	    boolean success = (file.delete());
       
   210 	    if (!success) {
       
   211 	        fail();
       
   212 	    }
       
   213 	    
       
   214 	    success = file2.renameTo(file);
       
   215 	    if (!success) {
       
   216 	        // File was not successfully renamed
       
   217 	    	fail();
       
   218 	    }
       
   219 	    
       
   220 
       
   221 		
       
   222 		// File (or directory) with old name
       
   223 	    
       
   224 	    
       
   225 	}
       
   226 }