First pass for read/write of Qt global/local preferences
authortimkelly
Mon, 08 Feb 2010 21:06:46 -0600
changeset 906 1b0436631b2f
parent 905 c9573e1f3013
child 907 7bf0e13219df
First pass for read/write of Qt global/local preferences
project/com.nokia.carbide.cpp.project.core.tests/.settings/org.eclipse.jdt.core.prefs
project/com.nokia.carbide.cpp.project.core.tests/META-INF/MANIFEST.MF
project/com.nokia.carbide.cpp.project.core.tests/src/com/nokia/carbide/cpp/project/core/tests/QtPropertiesTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project/com.nokia.carbide.cpp.project.core.tests/.settings/org.eclipse.jdt.core.prefs	Mon Feb 08 21:06:46 2010 -0600
@@ -0,0 +1,64 @@
+#Mon Feb 08 13:47:33 CST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
--- a/project/com.nokia.carbide.cpp.project.core.tests/META-INF/MANIFEST.MF	Mon Feb 08 13:53:22 2010 -0600
+++ b/project/com.nokia.carbide.cpp.project.core.tests/META-INF/MANIFEST.MF	Mon Feb 08 21:06:46 2010 -0600
@@ -16,6 +16,9 @@
  com.nokia.carbide.cpp.sdk.core,
  org.eclipse.cdt.core,
  com.nokia.carbide.cpp.project.ui,
- com.nokia.carbide.cpp.api.test.support;bundle-version="1.0.0"
+ com.nokia.carbide.cpp.api.test.support;bundle-version="1.0.0",
+ com.nokia.carbide.cpp.qt.core;bundle-version="1.4.0",
+ com.trolltech.qtcppproject;bundle-version="1.6.0",
+ com.trolltech.qtproject;bundle-version="1.0.1"
 Bundle-ActivationPolicy: lazy
 Export-Package: com.nokia.carbide.cpp.project.core.tests
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project/com.nokia.carbide.cpp.project.core.tests/src/com/nokia/carbide/cpp/project/core/tests/QtPropertiesTest.java	Mon Feb 08 21:06:46 2010 -0600
@@ -0,0 +1,169 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+
+package com.nokia.carbide.cpp.project.core.tests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import com.nokia.carbide.cpp.internal.qt.core.QtCorePlugin;
+import com.nokia.carbide.cpp.project.core.ProjectCorePlugin;
+import com.trolltech.qtcppproject.QtProjectPlugin;
+import com.trolltech.qtcppproject.preferences.PreferenceConstants;
+
+@SuppressWarnings("restriction")
+public class QtPropertiesTest extends TestCase {
+	
+	static int QtSDKCount = 0;
+	static String defaultQtVersionName = "";
+	
+	public void testReadQtPropertiesFirstTime() throws Exception {
+
+		IPreferenceStore store = QtProjectPlugin.getDefault().getPreferenceStore();
+		
+		assertNotNull("Can't get QtProjectPlugins prefs store.", store);
+		
+		QtSDKCount = store.getInt(PreferenceConstants.QTVERSION_COUNT);
+		assertEquals("There should be no Qt SDKs installed.", 0, QtSDKCount);
+
+		defaultQtVersionName = store.getString(PreferenceConstants.QTVERSION_DEFAULT);
+		assertEquals("", defaultQtVersionName);
+	}
+	
+	
+	public void testCreateQtSDKEntries() throws Exception {
+		
+		IPreferenceStore store = QtProjectPlugin.getDefault().getPreferenceStore();
+		
+		int count = store.getInt(PreferenceConstants.QTVERSION_COUNT);
+		
+		createQtSDKEntry(store, "TestSDK1", true);
+		createQtSDKEntry(store, "TestSDK2", true);
+		createQtSDKEntry(store, "TestSDK3", false);
+		createQtSDKEntry(store, "TestSDK4", false);
+		
+		store.setValue(PreferenceConstants.QT_AUTOSETMKSPEC, false);
+		store.setValue(PreferenceConstants.QT_AUTOSETMKCMD, false);
+		
+		count = store.getInt(PreferenceConstants.QTVERSION_COUNT);
+		assertEquals("Number of Qt SDKs count if off", count, QtSDKCount);
+		
+		int defaultSDK = store.getInt(PreferenceConstants.QTVERSION_DEFAULT); // zero-based index
+		assertEquals(1, defaultSDK);
+	}
+	
+	public void testCheckForDuplicateSDK() throws Exception {
+		
+		IPreferenceStore store = QtProjectPlugin.getDefault().getPreferenceStore();
+		
+		assertEquals(0, findSDKByName(store, "TestSDK1"));
+		assertEquals(3, findSDKByName(store, "TestSDK4"));
+		assertEquals(-1, findSDKByName(store, "foo"));
+	}
+	
+	public void testCreateProjectAndSetQtDefult() throws Exception {
+		// create a simple project
+		IProject project = null;
+		try {
+			project = ProjectCorePlugin.createProject("qtTestProject", null);
+			assertNotNull(project);
+			
+			QtCorePlugin.addQtNature(project, new NullProgressMonitor());
+			
+			
+		} catch (CoreException e) {
+			fail();
+		}
+		
+		// private data from QtProject.java
+		String QTVERSION = "com.trolltech.qtproject.properties.qtversion";
+
+		String version = project.getPersistentProperty(new QualifiedName("", QTVERSION));
+		
+		// save 
+		project.setPersistentProperty(new QualifiedName("", QTVERSION), "TestSDK1");
+
+			// read
+		version = project.getPersistentProperty(new QualifiedName("", QTVERSION));
+		assertEquals("TestSDK1", version);
+
+	}
+	
+	private void createQtSDKEntry(IPreferenceStore store, String name, boolean makeDefault){
+		QtSDKCount = store.getInt(PreferenceConstants.QTVERSION_COUNT);
+		
+		store.setValue(PreferenceConstants.QTVERSION_COUNT, QtSDKCount + 1); // # of table items, not zero based
+		store.setValue(PreferenceConstants.QTVERSION_NAME + "."
+				+ Integer.toString(QtSDKCount), name);
+		store.setValue(PreferenceConstants.QTVERSION_BINPATH + "."
+				+ Integer.toString(QtSDKCount), "T:\\epoc32\\tools\\qt");
+		store.setValue(PreferenceConstants.QTVERSION_INCLUDEPATH + "."
+				+ Integer.toString(QtSDKCount), "T:\\epoc32\\include\\mw");
+		
+		if (makeDefault){
+			store.setValue(PreferenceConstants.QTVERSION_DEFAULT, QtSDKCount);
+		}
+		
+		QtSDKCount = store.getInt(PreferenceConstants.QTVERSION_COUNT);
+
+	}
+	
+	/**
+	 * Check and see if an SDK exists by name and return its zero-based index. Return -1 if not found.
+	 * @return
+	 */
+	private int findSDKByName(IPreferenceStore store, String sdkName){
+		int foundIndex = -1;
+		
+		int count = store.getInt(PreferenceConstants.QTVERSION_COUNT);
+		for (int i = 0; i < count; i++) {
+			String nameKey = PreferenceConstants.QTVERSION_NAME + "."
+					+ Integer.toString(i);
+			String binpathKey = PreferenceConstants.QTVERSION_BINPATH + "."
+					+ Integer.toString(i);
+			String includepathKey = PreferenceConstants.QTVERSION_INCLUDEPATH
+					+ "." + Integer.toString(i);
+			String name = "";
+			//String binpath = "";
+			//String includepath = "";
+			if (store.contains(nameKey)) {
+				name = store.getString(nameKey);
+				if (name.equalsIgnoreCase(sdkName)){
+					foundIndex = i;
+					break;
+				}
+			}
+//			if (store.contains(binpathKey)) {
+//				binpath = store.getString(binpathKey);
+//				System.out.println("Binpath: " + binpath);
+//			}
+//			if (store.contains(includepathKey)) {
+//				includepath = store.getString(includepathKey);
+//				System.out.println("Inc Path: " + includepath);
+//			}
+		}
+		
+		return foundIndex;
+	}
+	
+	
+}