improve unicode tests

This commit is contained in:
Thomas Fussell 2017-04-13 10:58:40 -04:00
parent 8bf7d0c7a6
commit 46df18c12b
7 changed files with 35 additions and 13 deletions

View File

@ -109,6 +109,14 @@ public:
/// </summary> /// </summary>
std::string string() const; std::string string() const;
#ifdef _MSC_VER
/// <summary>
/// Create a wstring representing this path separated by the provided
/// separator or the system-default separator if not provided.
/// </summary>
std::wstring wstring() const;
#endif
/// <summary> /// <summary>
/// If this path is relative, append each component of this path /// If this path is relative, append each component of this path
/// to base_path and return the resulting absolute path. Otherwise, /// to base_path and return the resulting absolute path. Otherwise,

View File

@ -20,6 +20,8 @@
// //
// @license: http://www.opensource.org/licenses/mit-license.php // @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file // @author: see AUTHORS file
#include <codecvt>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <sys/stat.h> #include <sys/stat.h>
@ -207,6 +209,14 @@ std::string path::string() const
return internal_; return internal_;
} }
#ifdef _MSC_VER
std::wstring path::wstring() const
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> convert;
return convert.from_bytes(string());
}
#endif
std::vector<std::string> path::split() const std::vector<std::string> path::split() const
{ {
return split_path(internal_, guess_separator()); return split_path(internal_, guess_separator());

View File

@ -49,16 +49,16 @@ public:
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
xlnt::workbook wb; xlnt::workbook wb;
const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_filename_Λ.xlsx"; const auto path = LSTRING_LITERAL(XLNT_TEST_DATA_DIR) L"/9_unicode_Λ.xlsx";
wb.load(path); wb.load(path);
TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").value<std::string>(), "unicode!"); TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
#endif #endif
#ifndef __MINGW32__ #ifndef __MINGW32__
xlnt::workbook wb2; xlnt::workbook wb2;
const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_filename_Λ.xlsx"; const auto path2 = U8STRING_LITERAL(XLNT_TEST_DATA_DIR) u8"/9_unicode_Λ.xlsx";
wb2.load(path2); wb2.load(path2);
TS_ASSERT_EQUALS(wb2.active_sheet().cell("A1").value<std::string>(), "unicode!"); TS_ASSERT_EQUALS(wb2.active_sheet().cell("A1").value<std::string>(), u8"unicodê!");
#endif #endif
} }

View File

@ -26,7 +26,11 @@ public:
source_workbook.save(destination); source_workbook.save(destination);
source_workbook.save("temp.xlsx"); source_workbook.save("temp.xlsx");
std::ifstream source_stream(source.string(), std::ios::binary); #ifdef _MSC_VER
std::ifstream source_stream(source.wstring(), std::ios::binary);
#else
std::ifstream source_stream(source.string(), std::ios::binary);
#endif
return xml_helper::xlsx_archives_match(xlnt::detail::to_vector(source_stream), destination); return xml_helper::xlsx_archives_match(xlnt::detail::to_vector(source_stream), destination);
} }
@ -39,7 +43,12 @@ public:
std::vector<std::uint8_t> destination; std::vector<std::uint8_t> destination;
source_workbook.save(destination); source_workbook.save(destination);
#ifdef _MSC_VER
std::ifstream source_stream(source.wstring(), std::ios::binary);
#else
std::ifstream source_stream(source.string(), std::ios::binary); std::ifstream source_stream(source.string(), std::ios::binary);
#endif
const auto source_decrypted = xlnt::detail::decrypt_xlsx( const auto source_decrypted = xlnt::detail::decrypt_xlsx(
xlnt::detail::to_vector(source_stream), password); xlnt::detail::to_vector(source_stream), password);
@ -53,6 +62,7 @@ public:
"2_minimal", "2_minimal",
"3_default", "3_default",
"4_every_style", "4_every_style",
u8"9_unicode_Λ",
"10_comments_hyperlinks_formulae", "10_comments_hyperlinks_formulae",
"11_print_settings", "11_print_settings",
"12_advanced_properties" "12_advanced_properties"

View File

@ -68,12 +68,6 @@
namespace { namespace {
#ifdef _MSC_VER #ifdef _MSC_VER
std::wstring utf8_to_utf16(const std::string &utf8_string)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> convert;
return convert.from_bytes(utf8_string);
}
void open_stream(std::ifstream &stream, const std::wstring &path) void open_stream(std::ifstream &stream, const std::wstring &path)
{ {
stream.open(path, std::ios::binary); stream.open(path, std::ios::binary);
@ -86,12 +80,12 @@ void open_stream(std::ofstream &stream, const std::wstring &path)
void open_stream(std::ifstream &stream, const std::string &path) void open_stream(std::ifstream &stream, const std::string &path)
{ {
open_stream(stream, utf8_to_utf16(path)); open_stream(stream, xlnt::path(path).wstring());
} }
void open_stream(std::ofstream &stream, const std::string &path) void open_stream(std::ofstream &stream, const std::string &path)
{ {
open_stream(stream, utf8_to_utf16(path)); open_stream(stream, xlnt::path(path).wstring());
} }
#else #else
void open_stream(std::ifstream &stream, const std::string &path) void open_stream(std::ifstream &stream, const std::string &path)

Binary file not shown.