1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6  */
7 
8 #include "gnumeric_sheet_context.hpp"
9 #include "gnumeric_tokens.hpp"
10 #include "gnumeric_namespace_types.hpp"
11 #include "gnumeric_token_constants.hpp"
12 #include "mock_spreadsheet.hpp"
13 #include "session_context.hpp"
14 #include "orcus/types.hpp"
15 
16 #include <iostream>
17 #include <string>
18 #include <cstdlib>
19 
20 using namespace orcus;
21 using namespace std;
22 using namespace orcus::spreadsheet;
23 using namespace orcus::spreadsheet::mock;
24 
25 class mock_sheet_properties : public import_sheet_properties
26 {
27 public:
set_column_width(col_t col,double size,length_unit_t unit)28     virtual void set_column_width(col_t col, double size, length_unit_t unit)
29     {
30         assert(col == 2);
31         assert(size == 37.3);
32         assert(unit == length_unit_t::point);
33     }
34 
set_column_hidden(col_t,bool)35     virtual void set_column_hidden(col_t, bool)
36     {
37     }
38 
set_row_height(row_t row,double size,length_unit_t unit)39     virtual void set_row_height(row_t row, double size, length_unit_t unit)
40     {
41         assert(row == 4);
42         assert(size == 7.3);
43         assert(unit == length_unit_t::point);
44     }
45 
set_row_hidden(row_t,bool)46     virtual void set_row_hidden(row_t, bool)
47     {
48     }
49 };
50 
51 class mock_sheet : public import_sheet
52 {
53 public:
get_sheet_properties()54     virtual iface::import_sheet_properties* get_sheet_properties()
55     {
56         return &m_mock_properties;
57     }
58 
get_sheet_size() const59     virtual range_size_t get_sheet_size() const
60     {
61         range_size_t ret;
62         ret.rows = ret.columns = 0;
63         return ret;
64     }
65 
66 private:
67     mock_sheet_properties m_mock_properties;
68 };
69 
70 class mock_factory : public import_factory
71 {
72 public:
append_sheet(sheet_t,const char *,size_t)73     virtual iface::import_sheet* append_sheet(sheet_t, const char*, size_t)
74     {
75         return &m_mock_sheet;
76     }
77 private:
78     mock_sheet m_mock_sheet;
79 };
80 
test_column_width()81 void test_column_width()
82 {
83     mock_factory factory;
84     session_context cxt;
85 
86     orcus::gnumeric_sheet_context context(cxt, orcus::gnumeric_tokens, &factory, 0);
87     orcus::xmlns_id_t ns = NS_gnumeric_gnm;
88     orcus::xml_token_t parent = XML_Sheet;
89     orcus::xml_attrs_t parent_attr;
90     context.start_element(ns, parent, parent_attr);
91     {
92         orcus::xml_token_t elem = XML_Name;
93         orcus::xml_attrs_t attrs;
94         context.start_element(ns, elem, attrs);
95         context.characters("test", false);
96         context.end_element(ns, elem);
97     }
98     {
99         orcus::xml_token_t elem = XML_ColInfo;
100         orcus::xml_attrs_t attrs;
101         attrs.push_back(xml_token_attr_t(ns, XML_No, "2", false));
102         attrs.push_back(xml_token_attr_t(ns, XML_Unit, "37.3", false));
103         attrs.push_back(xml_token_attr_t(ns, XML_Unit, "37.3", false));
104         context.start_element(ns, elem, attrs);
105         context.end_element(ns, elem);
106     }
107     context.end_element(ns, parent);
108 }
109 
main()110 int main()
111 {
112     test_column_width();
113 
114     return EXIT_SUCCESS;
115 }
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
117