Spacing problem of namespaces in C++ unit testing
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Spacing problem of namespaces in C++ unit testing

  1. #1
    Join Date
    Dec 2010
    Posts
    642

    Spacing problem of namespaces in C++ unit testing

    Code:
        Code:
    
        #include "stdafx.h"
    
        using namespace System;
        using namespace System::Text;
        using namespace System::Collections::Generic;
        using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
         
    
        namespace PerfectSimTest1
        {
        	[TestClass]
        	public ref class CGameApplicationTest
        	{
        	private:
        		TestContext^ testContextInstance;
    
        	public: 
        		/// <summary>
        		///取得或設定提供目前測試回合
        		///的相關資訊與功能的測試內容。
        		///</summary>
        		property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
        		{
        			Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
        			{
        				return testContextInstance;
        			}
        			System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
        			{
        				testContextInstance = value;
        			}
        		};
    
        		#pragma region Additional test attributes
        		//
        		//您可以在撰寫測試時,使用下列的其他屬性:
        		//
        		//在執行類別中的第一項測試之前,先使用 ClassInitialize 執行程式碼
        		//[ClassInitialize()]
        		//static void MyClassInitialize(TestContext^ testContext) {};
        		//
        		//在執行類別中的所有測試之後,使用 ClassCleanup 執行程式碼
        		//[ClassCleanup()]
        		//static void MyClassCleanup() {};
        		//
        		//在執行每一項測試之前,先使用 TestInitialize 執行程式碼
        		//[TestInitialize()]
        		//void MyTestInitialize() {};
        		//
        		//在執行每一項測試之後,使用 TestCleanup 執行程式碼
        		//[TestCleanup()]
        		//void MyTestCleanup() {};
        		//
        		#pragma endregion 
    
        		[TestMethod]
        		void RunTest()
        		{
        			CGameApplication;
        			CGameApplication^ oCache = gcnew CGameApplication();
        			oCache->Run();
        			//
        			// TODO: 在此加入測試邏輯
        			//
        		};
        	};
        }
    The error being is CGameApplication can't be recognized, undefined or something.
    There is a space in between the project name such as "Simulation V2.0"
    When I do,
    using namespace Simulation V2.0 or using namespace "Simulation V2.0", the compiler complains.
    I have made a reference in the .NET section of the test project to no avail
    Please help
    Thanks
    Jack

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,591

    Re: Spacing problem of namespaces in C++ unit testing

    Of course, Simulation V2.0 is not a valid C++ or C++/CLI namespace name: The space isn't legal in an identifier, nor is the dot. And enclosed in double quotes it's even more invalid (in case that's even possible... ): These are just for string literals. How did that namespace name get created? As per my experience, the IDE should take care of converting problematic project names into valid namespace names. For instance, I have a project named 7segTest (not a valid C++ identifier due to the digit at the beginning) for which the IDE (VC++ 2010 Express) created a namespace named My7segTest - simple but effective.

    BTW, I don't see any instance of the offending namespace name in the code snippet you posted. How are they related?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Dec 2010
    Posts
    642

    Re: Spacing problem of namespaces in C++ unit testing

    Let me explain my procedure, I created a unit test project from the solution menu. I add a reference to the .NET framework.
    It says PerfectSim V5.0 in the reference list box, that is fine. But when I created a CGameApplication which is a class under the solution/project names
    It is underlined, meaning not recognized. Just don't know why.
    Thanks
    Jack

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,591

    Re: Spacing problem of namespaces in C++ unit testing

    I must admit I never used that testing framework, one of the reasons being that it simply isn't even part of the Express Edition I'm using. Nonetheless I'm gaining the impression that this actually isn't a C++/CLI issue, rather one regarding the testing framework. Even if it's a problem that the testing framework specifically fails to handle C++/CLI projects the way they get set up by the IDE, I still wouldn't regard that a C++/CLI issue.

    At any rate, we settled on that somthing containing a space and a dot is not a valid namespace name. And as pointed out above, the IDE usually converts project names that aren't valid namespace names into valid namespace names. It shouldn't be too complicated for you to find out what namespace the IDE created as the application namespace for your project. For instance, it should be obvious in class view:

    Name:  2012-09-07_023837.png
Views: 84
Size:  7.9 KB

    I hope that then, once you know the actual namespace created, there's a way you can set up the test framework to use that instead of the one it apparently has created itself by simply taking the project name.

    HTH

    Quote Originally Posted by lucky6969b View Post
    It says PerfectSim V5.0 in the reference list box, that is fine.
    Wow, the development of PerfectSim seems to progress at above light speed: from V2.0 to V5.0 within less than one day!
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center