Documentation

    Table of Content
    • CodePorting.Native Product Family
      • CodePorting.Native Cs2Cpp
        • Getting Started
          • Product Overview
          • Installation
          • Licensing
          • How to use CodePorting.Native Cs2Cpp
            • How to Use Command line to port and build Projects
            • How to Use GUI to port and build Projects
        • Developer Guide
          • Porting Simple C# Projects
            • Porting Simple Console Application
            • Porting Simple Library
            • Porting Simple NUnit Test
          • Porting Dependent C# Projects
            • Porting Dependent Console Application
            • Porting Dependent Library
            • Porting Dependent NUnit Test
          • Porting Complex C# Projects
            • How to Convert Complex C# Console Application to C++
            • How to Convert Complex C# Library to C++
            • How to Convert Complex C# NUnit Test to C++
          • What Converts to What
            • Abstract Classes
            • Auto Properties
            • Break Statements
            • Class Constructors
            • Continue Statements
            • Delegates
            • Do While Statemetns
            • Enums TypeCast
            • Enums
            • Events
            • Exceptions
            • Expected Exceptions
            • Finalizers
            • For Statements
            • ForEach Statements
            • Generic Classes
            • Generic Delegates
            • Generic Interfaces
            • Generic Methods
            • Generic Structs
            • If Statements
            • Indexers
            • Lambda Expressions
            • Methods
            • Nested Classes
            • Properties
            • Return Statements
            • Simple Class
            • Simple Interface
            • Simple Struct
            • Simple Test
            • Standard TypeCast
            • Static Class
            • Static Constructor
            • Static-Methods
            • Static Properties
            • Switch Statements
            • Test with Setup Methods
            • Throw Statements
            • Try Catch Finally Statements
            • Try Catch Statements
            • Try Finally Statements
            • Var Expressions
            • Virtual Methods
            • While Statements
          • CodePorting Native Cs2Cpp Attributes
          • CodePorting Native Cs2Cpp Configuration File
            • CodePorting.Native Cs2Cpp Configuration File Structure
            • Attributes in Configuration file
            • Configuration file Nodes
            • Configuration file Options
          • Memory Management Model
            • Using aliasing constructor to create a smart pointer
          • Cmake Support
          • Limitations and Bugs
            • Porter Limitations and Bugs
            • Library Limitations and Bugs
            • Cpp Code Injection
        • Release Notes
          • 2021
            • CodePorting.Native Cs2Cpp 21.4
            • CodePorting.Native Cs2Cpp 21.3
            • CodePorting.Native Cs2Cpp 21.2
            • CodePorting.Native Cs2Cpp 21.1
          • 2020
            • CodePorting.Native Cs2Cpp 20.12
            • CodePorting.Native Cs2Cpp 20.11
            • CodePorting.Native Cs2Cpp 20.10
            • CodePorting.Native Cs2Cpp 20.9
            • CodePorting.Native Cs2Cpp 20.8
            • CodePorting.Native Cs2Cpp 20.7
            • CodePorting.Native Cs2Cpp 20.6
            • CodePorting.Native Cs2Cpp 20.5
            • CodePorting.Native Cs2Cpp 20.4
            • CodePorting.Native Cs2Cpp 20.3
            • CodePorting.Native Cs2Cpp 20.2
            • CodePorting.Native Cs2Cpp 20.1
          • 2019
            • CodePorting.Native Cs2Cpp 19.1
            • CodePorting.Native Cs2Cpp 19.2
            • CodePorting.Native Cs2Cpp 19.3
            • CodePorting.Native Cs2Cpp 19.4
            • CodePorting.Native Cs2Cpp 19.4.1
            • CodePorting.Native Cs2Cpp 19.5
            • CodePorting.Native Cs2Cpp 19.6
            • CodePorting.Native Cs2Cpp 19.7
            • CodePorting.Native Cs2Cpp 19.8
            • CodePorting.Native Cs2Cpp 19.9
            • CodePorting.Native Cs2Cpp 19.10
            • CodePorting.Native Cs2Cpp 19.11
            • CodePorting.Native Cs2Cpp 19.12
          • 2018
            • CodePorting.Native Cs2Cpp 18.9
            • CodePorting.Native Cs2Cpp 18.9.1
            • CodePorting.Native Cs2Cpp 18.10
            • CodePorting.Native Cs2Cpp 18.11
            • CodePorting.Native Cs2Cpp 18.12
    1. Home
    2. CodePorting.Native Product Family
    3. CodePorting.Native Cs2Cpp
    4. Developer Guide
    5. Porting Simple C# Projects
    6. Porting Simple NUnit Test

    Porting Simple NUnit Test

    What's on this Page

      • Porting a simple NUnit test project

     

    Note that this example is built upon several assumptions, namely:
    • Porter is installed to C:\CodePorting.Native_Cs2Cpp_19.4 directory
    • A sample C# project is located in C:\SimpleNUnitTest directory
    • The output directory for the project is C:\output

    Porting a simple NUnit test project

    This example demonstrates how to port a C# NUnit test project. We’ll use pre-existing project from SimpleNUnitTest example located here.

    SimpleNUnitTest is a library project that contains NUnit tests. Porter translates C# NUnit library projects into C++ executable projects. SimpleNUnitTest project consists of a single .cs source file SimpleNUnitTest.cs and a project file SimpleNUnitTest.csproj. This project does not have any dependencies on other C# projects. SimpleNUnetTest project’s configuration file is pre-created, its name is SimpleNUnitTest.porter.config and it is located in the project’s directory SimpleNUnitTest. Let us have a closer look at the configuration file.

    SimpleNUnitTest.porter.config begins with an XML declaration, which specifies that the file contains an XML document    
    
    Then goes the XML root element <porter> which is mandatory for Porter configuration XML document  
    
        <porter>  
    
    Next, the default Porter configuration file is imported using <import> element. The default configuration will assign default values to all configuration options  
    
        <import config="porter.config"/>  
    
    Next, we want Porter to add some commands to the output CMakeLists.txt. We do that by adding <cmake_commands> element to the configuration file containing raw Cmake commands  
    
        <cmake_commands>  
          <![CDATA[    
    
    The first command sets the output directory for the executable binary by setting the corresponding property on the target ${PROJECT_NAME}_gtest  
    
          set_target_properties(${PROJECT_NAME}_gtest PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin")  
    
    Here ${PROJECT_NAME} is the name of the Cmake project and ${PROJECT_NAME}_gtest is the name of the main Cmake executable target.  
    
    Then the <cmake_commands> element is closed  
    
          ]]>  
       </cmake_commands>  
    
    Finally the XML document is finished with closing tag of the root element <porter>  
    
        </porter>

    With the C# project at hand and configuration file ready, we can convert the project.

    In order to covert SimpleNUnitTest project we run CMD and navigate to the directory with porter binary:

      >cd C:\CodePorting.Native_Cs2Cpp_19.4\bin\porter
    

    And run Porter:

     >CsToCppPorter.exe -c C:\SimpleNUnitTest\SimpleNUnitTest.porter.config C:\SimpleNUnitTest\SimpleNUnitTest.csproj C:\output
    

    Porter will print some logs of the porting process to the console window and when it finishes porting, directory C:\output will contain a directory named SimpleNUnitTest.Cpp containing the generated C++ source files and Cmake configuration files.

    Now we want to use Cmake to generate makefile/project files. Let it be a Visual Studio 2017 x86 project file. In CMD we navigate to the C:\output\SimpleNUnitTest.Cpp directory

     >cd C:\output\SimpleNUnitTest.Cpp
    

    And run Cmake in configuration mode:

      >Cmake --G "Visual Studio 15 2017"
    

    And now we can build the sources using either Cmake or Visual Studio. Let us use Cmake:

    >Cmake --build . --config Release
    

    When build finishes, directory D:\output\bin\Release should contain two files: SimpleNUnitTest.Cpp_gtest.exe, which has just been built from sources, and aspose_cpp_vc140.dll, which was copied from Porter installation directory during a post-build step. When we run SimpleNUnitTest.Cpp_gtest.exe it executes tests and prints results to the console window. The tests SimpleNUnitTest.Cpp_gtest.exe executes are similar to those in original C# project.