locked
visual studio 2010 unit testing Write file RRS feed

  • Question

  • For c++ Visual studio 2010 unit testing framework ,how can i creat a file and add the datas to file?

    I tried the below code after  Assert::AreEqual

    ofstream myfile;
    myfile.open ("example.txt");
    myfile << "Writing this to a file.\n";
     myfile.close();

    But this shows a linker error

    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_const_iterator<char,std::char_traits<char>,std::allocator<char> >): (0x02000019).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200003d).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >): (0x02000063).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_iterator<char,std::char_traits<char>,std::allocator<char> >): (0x02000080).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_val<char,std::allocator<char> >): (0x02000081).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_val<wchar_t,std::allocator<wchar_t> >): (0x02000083).
    1>LINK : fatal error LNK1255: link failed because of metadata errors

     

    After i compile with the option /clr it shows the abve error.

    Is there any other option to use in Unit testing with System::IO? or something to write to File?

    Wednesday, February 13, 2013 5:57 AM

All replies

  • For c++ Visual studio 2010 unit testing framework ,how can i creat a file and add the datas to file?

    I tried the below code after  Assert::AreEqual

    ofstream myfile;
    myfile.open ("example.txt");
    myfile << "Writing this to a file.\n";
     myfile.close();

    But this shows a linker error

    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_const_iterator<char,std::char_traits<char>,std::allocator<char> >): (0x02000019).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200003d).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >): (0x02000063).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_iterator<char,std::char_traits<char>,std::allocator<char> >): (0x02000080).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_val<char,std::allocator<char> >): (0x02000081).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_val<wchar_t,std::allocator<wchar_t> >): (0x02000083).
    1>LINK : fatal error LNK1255: link failed because of metadata errors

     

    After i compile with the option /clr it shows the abve error.

    Is there any other option to use in Unit testing with System::IO? or something to write to File?

    • Moved by Damon Zheng Tuesday, February 12, 2013 6:38 AM
    • Merged by Amanda Zhu Thursday, February 14, 2013 3:13 AM the same issue
    Friday, February 8, 2013 6:45 AM
  • Hello,

    Thanks for your participation.

    We have a specific forum for Visual Studio unit testing issues: http://social.msdn.microsoft.com/Forums/en-US/vsunittest/threads We will move this issue to that forum for better support.

    Best Regards,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 12, 2013 6:39 AM
  • Hi Aprabha,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 14, 2013 3:18 AM
  • Hello,

    Some preprocessor directives  may cause such issue if you are using the /clr option. Please set _HAS_ITERATOR_DEBUGGING and _SECURE_SCL to 0, and does it fix this issue?

    Thanks & Regards,

    Jian-Wei Yu [MSFT]

    Microsoft Online Community Support

    --------------------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Friday, February 15, 2013 5:11 AM
  • hi i tried by initializing _HAS_ITERATOR_DEBUGGING and _SECURE_SCL to  zero in the unit test case bu tthe ouptut still shows the below error

    1>  All outputs are up-to-date.
    1>ResourceCompile:
    1>  All outputs are up-to-date.
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_const_iterator<char,std::char_traits<char>,std::allocator<char> >): (0x02000019).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200003d).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >): (0x02000063).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_iterator<char,std::char_traits<char>,std::allocator<char> >): (0x02000080).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_val<char,std::allocator<char> >): (0x02000081).
    1>MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_val<wchar_t,std::allocator<wchar_t> >): (0x02000083).
    1>LINK : fatal error LNK1255: link failed because of metadata errors

    Please let me know how can i proceed.,

    Monday, February 18, 2013 8:16 AM