From 2c8ccdfcda3ebd8938f4c54c6502e4dec14132c0 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Tue, 3 Nov 2015 08:38:09 -0500 Subject: [PATCH] restructure source and clean up cmake scripts --- cmake/build | 7 --- cmake/generate-tests | 2 +- cmake/generate-tests.bat | 2 +- cmake/summarize_tests.py | 53 ++++++++++++++++ cmake/test | 11 ---- cmake/xlnt.cmake | 22 +++++-- cmake/xlnt.test.cmake | 43 ++++++++++--- include/xlnt/cell/cell.hpp | 2 +- include/xlnt/cell/cell_reference.hpp | 2 +- include/xlnt/{common => cell}/types.hpp | 0 .../{common => packaging}/relationship.hpp | 0 .../xlnt/{common => packaging}/zip_file.hpp | 0 .../{common => serialization}/encoding.hpp | 0 .../xlnt/serialization/excel_serializer.hpp | 2 +- include/xlnt/styles/alignment.hpp | 2 +- include/xlnt/styles/border.hpp | 4 +- include/xlnt/styles/color.hpp | 2 +- include/xlnt/styles/fill.hpp | 4 +- include/xlnt/styles/font.hpp | 2 +- include/xlnt/styles/protection.hpp | 2 +- include/xlnt/{common => utils}/datetime.hpp | 0 include/xlnt/{common => utils}/exceptions.hpp | 2 +- .../xlnt/{common => utils}/hash_combine.hpp | 0 include/xlnt/workbook/document_properties.hpp | 2 +- include/xlnt/workbook/workbook.hpp | 2 +- include/xlnt/worksheet/worksheet.hpp | 4 +- include/xlnt/xlnt.hpp | 12 ++-- source/cell/cell.cpp | 8 +-- source/cell/cell_reference.cpp | 4 +- {tests => source/cell/tests}/test_cell.hpp | 4 +- {tests => source/charts/tests}/test_chart.hpp | 0 source/detail/cell_impl.hpp | 8 +-- source/detail/constants.hpp | 2 +- .../drawing/tests}/test_drawing.hpp | 0 .../document_properties.cpp | 0 source/{workbook => packaging}/manifest.cpp | 0 source/{common => packaging}/relationship.cpp | 2 +- .../packaging/tests/test_core.hpp | 4 +- source/{common => packaging}/zip_file.cpp | 2 +- source/serialization/excel_serializer.cpp | 2 +- .../serialization/relationship_serializer.cpp | 4 +- .../serialization/tests}/test_read.hpp | 0 .../tests}/test_style_writer.hpp | 0 .../serialization/tests}/test_write.hpp | 0 .../tests}/test_write_workbook.hpp | 4 +- source/serialization/workbook_serializer.cpp | 8 +-- source/styles/number_format.cpp | 2 +- .../styles/tests}/test_number_style.hpp | 0 source/{common => utils}/datetime.cpp | 10 +++- source/{common => utils}/exceptions.cpp | 2 +- .../utils/tests}/test_datetime.hpp | 0 {tests => source/utils/tests}/test_units.hpp | 0 .../utils/tests}/test_zip_file.hpp | 0 source/workbook/named_range.cpp | 2 +- .../workbook/tests}/test_named_range.hpp | 0 .../workbook/tests/test_protection.hpp | 0 .../workbook/tests}/test_theme.hpp | 0 {tests => source/workbook/tests}/test_vba.hpp | 0 .../workbook/tests}/test_workbook.hpp | 0 source/workbook/workbook.cpp | 6 +- .../worksheet/tests}/test_datavalidation.hpp | 0 .../worksheet/tests}/test_worksheet.hpp | 0 source/worksheet/worksheet.cpp | 8 +-- tests/helpers/path_helper.hpp | 16 ++--- tests/test_meta.hpp | 10 ---- tests/test_strings.hpp | 60 ------------------- 66 files changed, 182 insertions(+), 170 deletions(-) delete mode 100755 cmake/build create mode 100644 cmake/summarize_tests.py delete mode 100755 cmake/test rename include/xlnt/{common => cell}/types.hpp (100%) rename include/xlnt/{common => packaging}/relationship.hpp (100%) rename include/xlnt/{common => packaging}/zip_file.hpp (100%) rename include/xlnt/{common => serialization}/encoding.hpp (100%) rename include/xlnt/{common => utils}/datetime.hpp (100%) rename include/xlnt/{common => utils}/exceptions.hpp (99%) rename include/xlnt/{common => utils}/hash_combine.hpp (100%) rename {tests => source/cell/tests}/test_cell.hpp (99%) rename {tests => source/charts/tests}/test_chart.hpp (100%) rename {tests => source/drawing/tests}/test_drawing.hpp (100%) rename source/{workbook => packaging}/document_properties.cpp (100%) rename source/{workbook => packaging}/manifest.cpp (100%) rename source/{common => packaging}/relationship.cpp (91%) rename tests/test_props.hpp => source/packaging/tests/test_core.hpp (97%) rename source/{common => packaging}/zip_file.cpp (99%) rename {tests => source/serialization/tests}/test_read.hpp (100%) rename {tests => source/serialization/tests}/test_style_writer.hpp (100%) rename {tests => source/serialization/tests}/test_write.hpp (100%) rename {tests => source/serialization/tests}/test_write_workbook.hpp (98%) rename {tests => source/styles/tests}/test_number_style.hpp (100%) rename source/{common => utils}/datetime.cpp (98%) rename source/{common => utils}/exceptions.cpp (97%) rename {tests => source/utils/tests}/test_datetime.hpp (100%) rename {tests => source/utils/tests}/test_units.hpp (100%) rename {tests => source/utils/tests}/test_zip_file.hpp (100%) rename {tests => source/workbook/tests}/test_named_range.hpp (100%) rename tests/test_password_hash.hpp => source/workbook/tests/test_protection.hpp (100%) rename {tests => source/workbook/tests}/test_theme.hpp (100%) rename {tests => source/workbook/tests}/test_vba.hpp (100%) rename {tests => source/workbook/tests}/test_workbook.hpp (100%) rename {tests => source/worksheet/tests}/test_datavalidation.hpp (100%) rename {tests => source/worksheet/tests}/test_worksheet.hpp (100%) delete mode 100644 tests/test_meta.hpp delete mode 100644 tests/test_strings.hpp diff --git a/cmake/build b/cmake/build deleted file mode 100755 index d1aac34e..00000000 --- a/cmake/build +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python3 - -import os -import subprocess - -os.chdir(os.path.dirname(os.path.abspath(__file__))) -subprocess.call(['sh', 'build-osx.sh']) diff --git a/cmake/generate-tests b/cmake/generate-tests index 1adcea1e..deaacd6c 100755 --- a/cmake/generate-tests +++ b/cmake/generate-tests @@ -1,2 +1,2 @@ cd ${0%/*} -../third-party/cxxtest/bin/cxxtestgen --runner=ErrorPrinter -o ../tests/runner-autogen.cpp ../tests/*.hpp \ No newline at end of file +../third-party/cxxtest/bin/cxxtestgen --runner=ErrorPrinter -o ../tests/runner-autogen.cpp ../tests/*.hpp ../source/*/tests/*.hpp \ No newline at end of file diff --git a/cmake/generate-tests.bat b/cmake/generate-tests.bat index fa988575..269338a2 100644 --- a/cmake/generate-tests.bat +++ b/cmake/generate-tests.bat @@ -1,2 +1,2 @@ cd %~dp0 -../third-party/cxxtest/bin/cxxtestgen --runner=ErrorPrinter -o ../tests/runner-autogen.cpp ../tests/*.hpp \ No newline at end of file +../third-party/cxxtest/bin/cxxtestgen --runner=ErrorPrinter -o ../tests/runner-autogen.cpp ../tests/*.hpp ../source/*/tests/*.hpp \ No newline at end of file diff --git a/cmake/summarize_tests.py b/cmake/summarize_tests.py new file mode 100644 index 00000000..abe581f9 --- /dev/null +++ b/cmake/summarize_tests.py @@ -0,0 +1,53 @@ +import os +import re +import sys + +def title_case_to_underscore(name): + a = re.compile('((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))') + return a.sub(r'_\1', name).lower() + +def list_tests(filename): + f = open(filename) + + in_class = False + class_name = '' + + for line in f: + if line.startswith('class '): + in_class = True + class_name = line.split(' ')[1][:-2] + if '(' in class_name: + class_name = class_name.split('(')[0] + continue + + if in_class and not (line.startswith(' ') or line.strip() == ''): + in_class = False + continue + + if line.lstrip().startswith('def test_'): + if in_class: + print('\t' + title_case_to_underscore(class_name) + '__' + line.split()[1].split('(')[0]) + else: + print('\t' + line.split()[1].split('(')[0]) + +def find_test_files(dir): + files = [] + + for f in os.listdir(dir): + if os.path.isdir(os.path.join(dir, f)): + files.extend(find_test_files(os.path.join(dir, f))) + elif os.path.isfile(os.path.join(dir, f)) and f.endswith('.py') and f.startswith('test_'): + files.append(os.path.join(dir, f)) + + return files + +def main(): + directory = sys.argv[1] if len(sys.argv) > 1 else os.path.dirname(os.path.abspath(__file__)) + test_files = find_test_files(directory) + for test_file in test_files: + print(test_file.split('openpyxl/')[1], end='') + list_tests(test_file) + print() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/cmake/test b/cmake/test deleted file mode 100755 index 651b687a..00000000 --- a/cmake/test +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python3 - -import os -import subprocess - -os.chdir(os.path.dirname(os.path.abspath(__file__))) -subprocess.call('./build') - -if os.path.isdir('../bin') and os.path.isfile('../bin/xlnt.test'): - os.chdir('../bin') - subprocess.call(['./xlnt.test']) diff --git a/cmake/xlnt.cmake b/cmake/xlnt.cmake index 89abb823..3886c250 100644 --- a/cmake/xlnt.cmake +++ b/cmake/xlnt.cmake @@ -9,41 +9,51 @@ FILE(GLOB ROOT_HEADERS ../include/xlnt/*.hpp) FILE(GLOB CELL_HEADERS ../include/xlnt/cell/*.hpp) FILE(GLOB CHARTS_HEADERS ../include/xlnt/charts/*.hpp) FILE(GLOB CHARTSHEET_HEADERS ../include/xlnt/chartsheet/*.hpp) -FILE(GLOB COMMON_HEADERS ../include/xlnt/common/*.hpp) FILE(GLOB DRAWING_HEADERS ../include/xlnt/drawing/*.hpp) FILE(GLOB FORUMULA_HEADERS ../include/xlnt/formula/*.hpp) FILE(GLOB PACKAGING_HEADERS ../include/xlnt/packaging/*.hpp) FILE(GLOB SERIALIZATION_HEADERS ../include/xlnt/serialization/*.hpp) FILE(GLOB STYLES_HEADERS ../include/xlnt/styles/*.hpp) +FILE(GLOB UTILS_HEADERS ../include/xlnt/utils/*.hpp) FILE(GLOB WORKBOOK_HEADERS ../include/xlnt/workbook/*.hpp) FILE(GLOB WORKSHEET_HEADERS ../include/xlnt/worksheet/*.hpp) FILE(GLOB DETAIL_HEADERS ../source/detail/*.hpp) -FILE(GLOB DETAIL_SOURCES ../source/detail/*.cpp) +SET(HEADERS ${ROOT_HEADERS} ${CELL_HEADERS} ${CHARTS_HEADERS} ${CHARTSHEET_HEADERS} ${DRAWING_HEADERS} ${FORMULA_HEADERS} ${PACKAGING_HEADERS} ${SERIALIZATION_HEADERS} ${STYLES_HEADERS} ${UTILS_HEADERS} ${WORKBOOK_HEADERS} ${WORKSHEET_HEADERS} ${DETAIL_HEADERS}) + FILE(GLOB CELL_SOURCES ../source/cell/*.cpp) FILE(GLOB CHARTS_SOURCES ../source/charts/*.cpp) FILE(GLOB CHARTSHEET_SOURCES ../source/chartsheet/*.cpp) -FILE(GLOB COMMON_SOURCES ../source/common/*.cpp) FILE(GLOB DRAWING_SOURCES ../source/drawing/*.cpp) FILE(GLOB FORUMULA_SOURCES ../source/formula/*.cpp) FILE(GLOB PACKAGING_SOURCES ../source/packaging/*.cpp) FILE(GLOB SERIALIZATION_SOURCES ../source/serialization/*.cpp) FILE(GLOB STYLES_SOURCES ../source/styles/*.cpp) +FILE(GLOB UTILS_SOURCES ../source/utils/*.cpp) FILE(GLOB WORKBOOK_SOURCES ../source/workbook/*.cpp) FILE(GLOB WORKSHEET_SOURCES ../source/worksheet/*.cpp) +FILE(GLOB DETAIL_SOURCES ../source/detail/*.cpp) -add_library(xlnt STATIC ${DETAIL_HEADERS} ${CELL_HEADERS} ${CHARTS_HEADERS} ${CHARTSHEET_HEADERS} ${COMMON_HEADERS} ${DRAWING_HEADERS} ${FORMULA_HEADERS} ${PACKAGING_HEADERS} ${SERIALIZATION_HEADERS} ${STYLES_HEADERS} ${WORKBOOK_HEADERS} ${WORKSHEET_HEADERS} ${DETAIL_SOURCES} ${CELL_SOURCES} ${CHARTS_SOURCES} ${CHARTSHEET_SOURCES} ${COMMON_SOURCES} ${DRAWING_SOURCES} ${FORMULA_SOURCES} ${PACKAGING_SOURCES} ${SERIALIZATION_SOURCES} ${STYLES_SOURCES} ${WORKBOOK_SOURCES} ${WORKSHEET_SOURCES} ../third-party/pugixml/src/pugixml.cpp ../third-party/miniz/miniz.c) +SET(SOURCES ${CELL_SOURCES} ${CHARTS_SOURCES} ${CHARTSHEET_SOURCES} ${DRAWING_SOURCES} ${FORMULA_SOURCES} ${PACKAGING_SOURCES} ${SERIALIZATION_SOURCES} ${STYLES_SOURCES} ${UTILS_SOURCES} ${WORKBOOK_SOURCES} ${WORKSHEET_SOURCES} ${DETAIL_SOURCES}) +SET(MINIZ ../third-party/miniz/miniz.c ../third-party/miniz/miniz.h) + +SET(PUGIXML ../third-party/pugixml/src/pugixml.hpp ../third-party/pugixml/src/pugixml.cpp ../third-party/pugixml/src/pugiconfig.hpp) + +add_library(xlnt STATIC ${HEADERS} ${SOURCES} ${MINIZ} ${PUGIXML}) + +source_group(xlnt FILES ${ROOT_HEADERS}) source_group(detail FILES ${DETAIL_HEADERS} ${DETAIL_SOURCES}) source_group(cell FILES ${CELL_HEADERS} ${CELL_SOURCES}) source_group(charts FILES ${CHARTS_HEADERS} ${CHARTS_SOURCES}) source_group(chartsheet FILES ${CHARTSHEET_HEADERS} ${CHARTSHEET_SOURCES}) -source_group(common FILES ${COMMON_HEADERS} ${COMMON_SOURCES}) source_group(drawing FILES ${DRAWING_HEADERS} ${DRAWING_SOURCES}) source_group(formula FILES ${FORUMULA_HEADERS} ${FORUMULA_SOURCES}) source_group(packaging FILES ${PACKAGING_HEADERS} ${PACKAGING_SOURCES}) source_group(serialization FILES ${SERIALIZATION_HEADERS} ${SERIALIZATION_SOURCES}) source_group(styles FILES ${STYLES_HEADERS} ${STYLES_SOURCES}) +source_group(utils FILES ${UTILS_HEADERS} ${UTILS_SOURCES}) source_group(workbook FILES ${WORKBOOK_HEADERS} ${WORKBOOK_SOURCES}) source_group(worksheet FILES ${WORKSHEET_HEADERS} ${WORKSHEET_SOURCES}) -source_group(third-party FILES ../third-party/pugixml/src/pugixml.cpp ../third-party/miniz/miniz.c) +source_group(third-party\\miniz FILES ${MINIZ}) +source_group(third-party\\pugixml FILES ${PUGIXML}) diff --git a/cmake/xlnt.test.cmake b/cmake/xlnt.test.cmake index 2ea886fc..0b339cd6 100644 --- a/cmake/xlnt.test.cmake +++ b/cmake/xlnt.test.cmake @@ -2,28 +2,57 @@ project(xlnt.test) include_directories(../include) include_directories(../source) -include_directories(../third-party/pugixml/src) +include_directories(../tests) include_directories(../third-party/cxxtest) +include_directories(../third-party/pugixml/src) + +FILE(GLOB CELL_TESTS ../source/cell/tests/test_*.hpp) +FILE(GLOB CHARTS_TESTS ../source/charts/tests/test_*.hpp) +FILE(GLOB CHARTSHEET_TESTS ../source/chartsheet/tests/test_*.hpp) +FILE(GLOB DRAWING_TESTS ../source/drawing/tests/test_*.hpp) +FILE(GLOB FORMULA_TESTS ../source/formula/tests/test_*.hpp) +FILE(GLOB PACKAGING_TESTS ../source/packaging/tests/test_*.hpp) +FILE(GLOB SERIALIZATION_TESTS ../source/serialization/tests/test_*.hpp) +FILE(GLOB STYLES_TESTS ../source/styles/tests/test_*.hpp) +FILE(GLOB UTILS_TESTS ../source/utils/tests/test_*.hpp) +FILE(GLOB WORKBOOK_TESTS ../source/workbook/tests/test_*.hpp) +FILE(GLOB WORKSHEET_TESTS ../source/worksheet/tests/test_*.hpp) + +SET(TESTS ${CELL_TESTS} ${CHARTS_TESTS} ${CHARTSHEET_TESTS} ${DRAWING_TESTS} ${FORMULA_TESTS} ${PACKAGING_TESTS} ${SERIALIZATION_TESTS} ${STYLES_TESTS} ${UTILS_TESTS} ${WORKBOOK_TESTS} ${WORKSHEET_TESTS}) -FILE(GLOB TEST_HEADERS ../tests/*.hpp) FILE(GLOB TEST_HELPERS_HEADERS ../tests/helpers/*.hpp) FILE(GLOB TEST_HELPERS_SOURCES ../tests/helpers/*.cpp) -add_executable(xlnt.test ../tests/runner-autogen.cpp ${TEST_HEADERS} ${TEST_HELPERS_HEADERS} ${TEST_HELPERS_SOURCES}) +SET(TEST_HELPERS ${TEST_HELPERS_HEADERS} ${TEST_HELPERS_SOURCES}) -source_group(runner FILES ../tests/runner-autogen.cpp) -source_group(tests FILES ${TEST_HEADERS}) -source_group(helpers FILES ${TEST_HELPERS_HEADERS} ${TEST_HELPERS_SOURCES}) +SET(RUNNER ../tests/runner-autogen.cpp) + +add_executable(xlnt.test ${TEST_HELPERS} ${TESTS} ${RUNNER} ) + +source_group(helpers FILES ${TEST_HELPERS}) +source_group(tests\\cell FILES ${CELL_TESTS}) +source_group(tests\\charts FILES ${CHARTS_TESTS}) +source_group(tests\\chartsheet FILES ${CHARTSHEET_TESTS}) +source_group(tests\\drawing FILES ${DRAWING_TESTS}) +source_group(tests\\formula FILES ${FORMULA_TESTS}) +source_group(tests\\packaging FILES ${PACKAGING_TESTS}) +source_group(tests\\serialization FILES ${SERIALIZATION_TESTS}) +source_group(tests\\styles FILES ${STYLES_TESTS}) +source_group(tests\\utils FILES ${UTILS_TESTS}) +source_group(tests\\workbook FILES ${WORKBOOK_TESTS}) +source_group(tests\\worksheet FILES ${WORKSHEET_TESTS}) +source_group(runner FILES ${RUNNER}) target_link_libraries(xlnt.test xlnt) +# Needed for PathFileExists in path_helper (test helper) if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") target_link_libraries(xlnt.test Shlwapi) endif() add_custom_target (generate-test-runner COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate-tests - COMMENT "Generating test runner tests/runner-autogen.cpp" + COMMENT "Generating test runner ${RUNNER}" ) add_dependencies(xlnt.test generate-test-runner) diff --git a/include/xlnt/cell/cell.hpp b/include/xlnt/cell/cell.hpp index 367dc364..b4933248 100644 --- a/include/xlnt/cell/cell.hpp +++ b/include/xlnt/cell/cell.hpp @@ -27,7 +27,7 @@ #include #include -#include +#include namespace xlnt { diff --git a/include/xlnt/cell/cell_reference.hpp b/include/xlnt/cell/cell_reference.hpp index e9990cda..e08edc26 100644 --- a/include/xlnt/cell/cell_reference.hpp +++ b/include/xlnt/cell/cell_reference.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include namespace xlnt { diff --git a/include/xlnt/common/types.hpp b/include/xlnt/cell/types.hpp similarity index 100% rename from include/xlnt/common/types.hpp rename to include/xlnt/cell/types.hpp diff --git a/include/xlnt/common/relationship.hpp b/include/xlnt/packaging/relationship.hpp similarity index 100% rename from include/xlnt/common/relationship.hpp rename to include/xlnt/packaging/relationship.hpp diff --git a/include/xlnt/common/zip_file.hpp b/include/xlnt/packaging/zip_file.hpp similarity index 100% rename from include/xlnt/common/zip_file.hpp rename to include/xlnt/packaging/zip_file.hpp diff --git a/include/xlnt/common/encoding.hpp b/include/xlnt/serialization/encoding.hpp similarity index 100% rename from include/xlnt/common/encoding.hpp rename to include/xlnt/serialization/encoding.hpp diff --git a/include/xlnt/serialization/excel_serializer.hpp b/include/xlnt/serialization/excel_serializer.hpp index cd7d36bc..bb70a796 100644 --- a/include/xlnt/serialization/excel_serializer.hpp +++ b/include/xlnt/serialization/excel_serializer.hpp @@ -28,7 +28,7 @@ #include #include -#include +#include namespace xlnt { diff --git a/include/xlnt/styles/alignment.hpp b/include/xlnt/styles/alignment.hpp index 0f14d368..33710e68 100644 --- a/include/xlnt/styles/alignment.hpp +++ b/include/xlnt/styles/alignment.hpp @@ -23,7 +23,7 @@ // @author: see AUTHORS file #pragma once -#include +#include namespace xlnt { diff --git a/include/xlnt/styles/border.hpp b/include/xlnt/styles/border.hpp index db354738..1ce3ddda 100644 --- a/include/xlnt/styles/border.hpp +++ b/include/xlnt/styles/border.hpp @@ -26,8 +26,8 @@ #include #include -#include "side.hpp" -#include "../common/hash_combine.hpp" +#include +#include namespace xlnt { diff --git a/include/xlnt/styles/color.hpp b/include/xlnt/styles/color.hpp index 879278d7..b46c2493 100644 --- a/include/xlnt/styles/color.hpp +++ b/include/xlnt/styles/color.hpp @@ -25,7 +25,7 @@ #include -#include +#include namespace xlnt { diff --git a/include/xlnt/styles/fill.hpp b/include/xlnt/styles/fill.hpp index 1e61cadf..99c4ce03 100644 --- a/include/xlnt/styles/fill.hpp +++ b/include/xlnt/styles/fill.hpp @@ -23,8 +23,8 @@ // @author: see AUTHORS file #pragma once -#include "../common/hash_combine.hpp" -#include "../styles/color.hpp" +#include +#include namespace xlnt { diff --git a/include/xlnt/styles/font.hpp b/include/xlnt/styles/font.hpp index b0da3a2f..df040e80 100644 --- a/include/xlnt/styles/font.hpp +++ b/include/xlnt/styles/font.hpp @@ -25,7 +25,7 @@ #include -#include +#include #include namespace xlnt { diff --git a/include/xlnt/styles/protection.hpp b/include/xlnt/styles/protection.hpp index 42286c6d..136132cb 100644 --- a/include/xlnt/styles/protection.hpp +++ b/include/xlnt/styles/protection.hpp @@ -25,7 +25,7 @@ #include -#include +#include namespace xlnt { diff --git a/include/xlnt/common/datetime.hpp b/include/xlnt/utils/datetime.hpp similarity index 100% rename from include/xlnt/common/datetime.hpp rename to include/xlnt/utils/datetime.hpp diff --git a/include/xlnt/common/exceptions.hpp b/include/xlnt/utils/exceptions.hpp similarity index 99% rename from include/xlnt/common/exceptions.hpp rename to include/xlnt/utils/exceptions.hpp index d8c3ee36..c44c8e73 100644 --- a/include/xlnt/common/exceptions.hpp +++ b/include/xlnt/utils/exceptions.hpp @@ -25,7 +25,7 @@ #include #include -#include +#include namespace xlnt { diff --git a/include/xlnt/common/hash_combine.hpp b/include/xlnt/utils/hash_combine.hpp similarity index 100% rename from include/xlnt/common/hash_combine.hpp rename to include/xlnt/utils/hash_combine.hpp diff --git a/include/xlnt/workbook/document_properties.hpp b/include/xlnt/workbook/document_properties.hpp index ed56a670..f4866eac 100644 --- a/include/xlnt/workbook/document_properties.hpp +++ b/include/xlnt/workbook/document_properties.hpp @@ -25,7 +25,7 @@ #include -#include +#include namespace xlnt { diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index a4f87f4f..b09b0ce7 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -29,7 +29,7 @@ #include #include -#include +#include namespace xlnt { diff --git a/include/xlnt/worksheet/worksheet.hpp b/include/xlnt/worksheet/worksheet.hpp index 66a43b1f..a5c0e9a5 100644 --- a/include/xlnt/worksheet/worksheet.hpp +++ b/include/xlnt/worksheet/worksheet.hpp @@ -29,8 +29,8 @@ #include #include -#include -#include +#include +#include #include namespace xlnt { diff --git a/include/xlnt/xlnt.hpp b/include/xlnt/xlnt.hpp index 7a7207a1..16f32ef1 100644 --- a/include/xlnt/xlnt.hpp +++ b/include/xlnt/xlnt.hpp @@ -38,12 +38,10 @@ const std::string download_url = "https://github.com/tfussell/xlnt/archive/maste #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -54,6 +52,8 @@ const std::string download_url = "https://github.com/tfussell/xlnt/archive/maste #include #include #include +#include +#include #include #include #include diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index 2dd75e31..6b592f61 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -5,15 +5,15 @@ #include #include #include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include #include -#include #include #include diff --git a/source/cell/cell_reference.cpp b/source/cell/cell_reference.cpp index 1fcf5305..85dbbf8f 100644 --- a/source/cell/cell_reference.cpp +++ b/source/cell/cell_reference.cpp @@ -1,10 +1,10 @@ #include #include -#include +#include #include -#include "detail/constants.hpp" +#include namespace xlnt { diff --git a/tests/test_cell.hpp b/source/cell/tests/test_cell.hpp similarity index 99% rename from tests/test_cell.hpp rename to source/cell/tests/test_cell.hpp index 62cb4b73..46f46ba0 100644 --- a/tests/test_cell.hpp +++ b/source/cell/tests/test_cell.hpp @@ -7,14 +7,14 @@ #include #include #include -#include -#include #include #include #include #include #include #include +#include +#include #include #include #include diff --git a/tests/test_chart.hpp b/source/charts/tests/test_chart.hpp similarity index 100% rename from tests/test_chart.hpp rename to source/charts/tests/test_chart.hpp diff --git a/source/detail/cell_impl.hpp b/source/detail/cell_impl.hpp index f494a9a1..846bf3e5 100644 --- a/source/detail/cell_impl.hpp +++ b/source/detail/cell_impl.hpp @@ -4,10 +4,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include "comment_impl.hpp" diff --git a/source/detail/constants.hpp b/source/detail/constants.hpp index d828b80b..2ce387ac 100644 --- a/source/detail/constants.hpp +++ b/source/detail/constants.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace xlnt { diff --git a/tests/test_drawing.hpp b/source/drawing/tests/test_drawing.hpp similarity index 100% rename from tests/test_drawing.hpp rename to source/drawing/tests/test_drawing.hpp diff --git a/source/workbook/document_properties.cpp b/source/packaging/document_properties.cpp similarity index 100% rename from source/workbook/document_properties.cpp rename to source/packaging/document_properties.cpp diff --git a/source/workbook/manifest.cpp b/source/packaging/manifest.cpp similarity index 100% rename from source/workbook/manifest.cpp rename to source/packaging/manifest.cpp diff --git a/source/common/relationship.cpp b/source/packaging/relationship.cpp similarity index 91% rename from source/common/relationship.cpp rename to source/packaging/relationship.cpp index ffad578a..8a030d6d 100644 --- a/source/common/relationship.cpp +++ b/source/packaging/relationship.cpp @@ -1,4 +1,4 @@ -#include +#include namespace xlnt { diff --git a/tests/test_props.hpp b/source/packaging/tests/test_core.hpp similarity index 97% rename from tests/test_props.hpp rename to source/packaging/tests/test_core.hpp index e6f13590..13963824 100644 --- a/tests/test_props.hpp +++ b/source/packaging/tests/test_core.hpp @@ -6,8 +6,8 @@ #include #include -#include "helpers/path_helper.hpp" -#include "helpers/helper.hpp" +#include +#include class test_props : public CxxTest::TestSuite { diff --git a/source/common/zip_file.cpp b/source/packaging/zip_file.cpp similarity index 99% rename from source/common/zip_file.cpp rename to source/packaging/zip_file.cpp index a19c406a..850558e0 100644 --- a/source/common/zip_file.cpp +++ b/source/packaging/zip_file.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace { diff --git a/source/serialization/excel_serializer.cpp b/source/serialization/excel_serializer.cpp index 46062476..1d316dfe 100644 --- a/source/serialization/excel_serializer.cpp +++ b/source/serialization/excel_serializer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/source/serialization/relationship_serializer.cpp b/source/serialization/relationship_serializer.cpp index d419b8cf..8b1e77e1 100644 --- a/source/serialization/relationship_serializer.cpp +++ b/source/serialization/relationship_serializer.cpp @@ -1,7 +1,7 @@ #include -#include -#include +#include +#include #include #include diff --git a/tests/test_read.hpp b/source/serialization/tests/test_read.hpp similarity index 100% rename from tests/test_read.hpp rename to source/serialization/tests/test_read.hpp diff --git a/tests/test_style_writer.hpp b/source/serialization/tests/test_style_writer.hpp similarity index 100% rename from tests/test_style_writer.hpp rename to source/serialization/tests/test_style_writer.hpp diff --git a/tests/test_write.hpp b/source/serialization/tests/test_write.hpp similarity index 100% rename from tests/test_write.hpp rename to source/serialization/tests/test_write.hpp diff --git a/tests/test_write_workbook.hpp b/source/serialization/tests/test_write_workbook.hpp similarity index 98% rename from tests/test_write_workbook.hpp rename to source/serialization/tests/test_write_workbook.hpp index 65bb5210..d406e550 100644 --- a/tests/test_write_workbook.hpp +++ b/source/serialization/tests/test_write_workbook.hpp @@ -3,10 +3,10 @@ #include #include -#include #include +#include -#include "helpers/path_helper.hpp" +#include class test_write_workbook : public CxxTest::TestSuite { diff --git a/source/serialization/workbook_serializer.cpp b/source/serialization/workbook_serializer.cpp index a86a5f15..db1f1c31 100644 --- a/source/serialization/workbook_serializer.cpp +++ b/source/serialization/workbook_serializer.cpp @@ -1,11 +1,11 @@ #include +#include #include -#include -#include -#include #include #include +#include +#include #include #include #include @@ -13,7 +13,7 @@ #include #include -#include "detail/constants.hpp" +#include namespace { diff --git a/source/styles/number_format.cpp b/source/styles/number_format.cpp index 08894106..18edd7cc 100644 --- a/source/styles/number_format.cpp +++ b/source/styles/number_format.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include namespace { diff --git a/tests/test_number_style.hpp b/source/styles/tests/test_number_style.hpp similarity index 100% rename from tests/test_number_style.hpp rename to source/styles/tests/test_number_style.hpp diff --git a/source/common/datetime.cpp b/source/utils/datetime.cpp similarity index 98% rename from source/common/datetime.cpp rename to source/utils/datetime.cpp index e1c977c1..ac986edb 100644 --- a/source/common/datetime.cpp +++ b/source/utils/datetime.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include namespace { @@ -36,14 +36,18 @@ time time::from_number(long double raw_time) result.second = (int)fractional_part; fractional_part = 1000000 * (fractional_part - result.second); result.microsecond = (int)fractional_part; + if (result.microsecond == 999999 && fractional_part - result.microsecond > 0.5) { result.microsecond = 0; result.second += 1; + if (result.second == 60) { result.second = 0; result.minute += 1; + + //TODO: too much nesting if (result.minute == 60) { result.minute = 0; @@ -51,6 +55,7 @@ time time::from_number(long double raw_time) } } } + return result; } @@ -92,6 +97,7 @@ datetime datetime::from_number(long double raw_time, calendar base_date) { auto date_part = date::from_number((int)raw_time, base_date); auto time_part = time::from_number(raw_time); + return datetime(date_part.year, date_part.month, date_part.day, time_part.hour, time_part.minute, time_part.second, time_part.microsecond); } @@ -122,6 +128,7 @@ time::time(const std::string &time_string) : hour(0), minute(0), second(0), micr colon_index = remaining.find(':'); minute = std::stoi(remaining.substr(0, colon_index)); colon_index = remaining.find(':'); + if (colon_index != std::string::npos) { remaining = remaining.substr(colon_index + 1); @@ -139,6 +146,7 @@ long double time::to_number() const auto number = microseconds / (24.0L * microseconds_per_hour); auto hundred_billion = static_cast(1e9) * 100; number = std::floor(number * hundred_billion + 0.5L) / hundred_billion; + return number; } diff --git a/source/common/exceptions.cpp b/source/utils/exceptions.cpp similarity index 97% rename from source/common/exceptions.cpp rename to source/utils/exceptions.cpp index f5782e6b..6693d10a 100644 --- a/source/common/exceptions.cpp +++ b/source/utils/exceptions.cpp @@ -1,4 +1,4 @@ -#include +#include namespace xlnt { diff --git a/tests/test_datetime.hpp b/source/utils/tests/test_datetime.hpp similarity index 100% rename from tests/test_datetime.hpp rename to source/utils/tests/test_datetime.hpp diff --git a/tests/test_units.hpp b/source/utils/tests/test_units.hpp similarity index 100% rename from tests/test_units.hpp rename to source/utils/tests/test_units.hpp diff --git a/tests/test_zip_file.hpp b/source/utils/tests/test_zip_file.hpp similarity index 100% rename from tests/test_zip_file.hpp rename to source/utils/tests/test_zip_file.hpp diff --git a/source/workbook/named_range.cpp b/source/workbook/named_range.cpp index 67cab343..2fa5b9a2 100644 --- a/source/workbook/named_range.cpp +++ b/source/workbook/named_range.cpp @@ -1,6 +1,6 @@ +#include #include -#include #include #include diff --git a/tests/test_named_range.hpp b/source/workbook/tests/test_named_range.hpp similarity index 100% rename from tests/test_named_range.hpp rename to source/workbook/tests/test_named_range.hpp diff --git a/tests/test_password_hash.hpp b/source/workbook/tests/test_protection.hpp similarity index 100% rename from tests/test_password_hash.hpp rename to source/workbook/tests/test_protection.hpp diff --git a/tests/test_theme.hpp b/source/workbook/tests/test_theme.hpp similarity index 100% rename from tests/test_theme.hpp rename to source/workbook/tests/test_theme.hpp diff --git a/tests/test_vba.hpp b/source/workbook/tests/test_vba.hpp similarity index 100% rename from tests/test_vba.hpp rename to source/workbook/tests/test_vba.hpp diff --git a/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp similarity index 100% rename from tests/test_workbook.hpp rename to source/workbook/tests/test_workbook.hpp diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index 2c2db2ae..aa4bd11d 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -4,10 +4,9 @@ #include #include -#include -#include -#include #include +#include +#include #include #include #include @@ -16,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/tests/test_datavalidation.hpp b/source/worksheet/tests/test_datavalidation.hpp similarity index 100% rename from tests/test_datavalidation.hpp rename to source/worksheet/tests/test_datavalidation.hpp diff --git a/tests/test_worksheet.hpp b/source/worksheet/tests/test_worksheet.hpp similarity index 100% rename from tests/test_worksheet.hpp rename to source/worksheet/tests/test_worksheet.hpp diff --git a/source/worksheet/worksheet.cpp b/source/worksheet/worksheet.cpp index 8fba4e68..b56f2d76 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -3,10 +3,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/tests/helpers/path_helper.hpp b/tests/helpers/path_helper.hpp index bde1177d..f52ce6e7 100644 --- a/tests/helpers/path_helper.hpp +++ b/tests/helpers/path_helper.hpp @@ -5,14 +5,14 @@ #include #include +#include + #ifdef __APPLE__ #include #include -#elif defined(_WIN32) -#define NOMINMAX +#elif defined(_MSC_VER) #include -#include -#else +#elif defined(__linux) #include #include #include @@ -67,7 +67,7 @@ public: throw std::runtime_error("buffer too small, " + std::to_string(path.size()) + ", should be: " + std::to_string(size)); -#elif defined(_WIN32) +#elif defined(_MSC_VER) std::array buffer; DWORD result = GetModuleFileName(nullptr, buffer.data(), (DWORD)buffer.size()); @@ -113,14 +113,14 @@ public: } static bool FileExists(const std::string &path) - { - -#ifdef _WIN32 + { +#ifdef _MSC_VER std::wstring path_wide(path.begin(), path.end()); return PathFileExists(path_wide.c_str()) && !PathIsDirectory(path_wide.c_str()); #else + try { struct stat fileAtt; diff --git a/tests/test_meta.hpp b/tests/test_meta.hpp deleted file mode 100644 index c83c8f5e..00000000 --- a/tests/test_meta.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include - -#include - -class test_meta : public CxxTest::TestSuite -{ -}; diff --git a/tests/test_strings.hpp b/tests/test_strings.hpp deleted file mode 100644 index b1dc1aaa..00000000 --- a/tests/test_strings.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#include -#include - -#include - -class test_strings : public CxxTest::TestSuite -{ -public: - test_strings() - { - - } - - void test_create_string_table() - { - /*wb = Workbook() - ws = wb.create_sheet() - ws.cell("B12").value = "hello" - ws.cell("B13").value = "world" - ws.cell("D28").value = "hello" - table = create_string_table(wb) - TS_ASSERT_EQUALS({"hello": 1, "world" : 0}, table)*/ - } - - void test_read_string_table() - { - /*handle = open(os.path.join(DATADIR, "reader", "sharedStrings.xml")) - try : - content = handle.read() - string_table = read_string_table(content) - TS_ASSERT_EQUALS({0: "This is cell A1 in Sheet 1", 1 : "This is cell G5"}, string_table) - finally : - handle.close()*/ - } - - void test_empty_string() - { - /*handle = open(os.path.join(DATADIR, "reader", "sharedStrings-emptystring.xml")) - try : - content = handle.read() - string_table = read_string_table(content) - TS_ASSERT_EQUALS({0: "Testing empty cell", 1 : ""}, string_table) - finally : - handle.close()*/ - } - - void test_formatted_string_table() - { - /*handle = open(os.path.join(DATADIR, "reader", "shared-strings-rich.xml")) - try : - content = handle.read() - string_table = read_string_table(content) - TS_ASSERT_EQUALS({0: "Welcome", 1 : "to the best shop in town", - 2 : " let"s play "}, string_table) - finally : - handle.close()*/ - } -};