ogr/dataset/TsDataSet.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/unittest/ogr/dataset/TsDataSet.cpp
22 
23  \brief A test suite for the DataSet Class.
24 
25  */
26 
27 // TerraLib
28 #include "../../Config.h"
29 #include <terralib/ogr/DataSet.h>
33 #include <terralib/datatype.h>
36 
37 // STL
38 #include <iostream>
39 #include <exception>
40 
41 // Boost
42 #include <boost/test/unit_test.hpp>
43 
44 std::unique_ptr<te::da::DataSet> GetDataSet()
45 {
46  std::string data_dir = TERRALIB_DATA_DIR;
47 
48  std::string filename(data_dir + "/shape/munic_goias.shp");
49 
50  std::string srcInfo ("file://" + filename);
51 
52  te::da::DataSourcePtr dataSource(te::da::DataSourceFactory::make("OGR", srcInfo));
53  dataSource->open();
54 
55  std::string inDsetName = "munic_goias";
56  return dataSource->getDataSet(inDsetName);
57 }
58 
59 
60 
61 BOOST_AUTO_TEST_SUITE( dataSet_tests )
62 
63 BOOST_AUTO_TEST_CASE( moveBeforeFirst_test )
64 {
65  std::unique_ptr<te::da::DataSet> dataSet = GetDataSet();
66  dataSet->moveBeforeFirst();
67  BOOST_CHECK(dataSet->isBeforeBegin());
68 }
69 
70 BOOST_AUTO_TEST_CASE( moveFirst_test )
71 {
72  std::unique_ptr<te::da::DataSet> dataSet = GetDataSet();
73  dataSet->moveFirst();
74  BOOST_CHECK(dataSet->isAtBegin());
75 }
76 
77 BOOST_AUTO_TEST_CASE( moveLast_test )
78 {
79  std::unique_ptr<te::da::DataSet> dataSet = GetDataSet();
80  dataSet->moveLast();
81  BOOST_CHECK(dataSet->isAtEnd());
82 }
83 
85 {
86  std::unique_ptr<te::da::DataSet> dataSet = GetDataSet();
87 
88  if(dataSet->move(8))
89  {
90  int id = dataSet->getInt32(0);
91  std::cout << std::endl
92  << "ID = " << boost::lexical_cast<std::string>(id)
93  << std::endl;
94  }
95  else
96  {
97  std::cout << std::endl
98  << "ID not found."
99  << std::endl;
100  }
101 
102  if(dataSet->move(20))
103  {
104  int id = dataSet->getInt32(0);
105  std::cout << std::endl
106  << "ID = " << boost::lexical_cast<std::string>(id)
107  << std::endl;
108  }
109  else
110  {
111  std::cout << std::endl
112  << "ID not found."
113  << std::endl;
114  }
115 
116  if(dataSet->move(5000))
117  {
118  int id = dataSet->getInt32(0);
119  std::cout << std::endl
120  << "ID = " << boost::lexical_cast<std::string>(id)
121  << std::endl;
122  }
123  else
124  {
125  std::cout << std::endl
126  << "ID not found."
127  << std::endl;
128  }
129 }
130 
131 BOOST_AUTO_TEST_CASE( moveNext_test )
132 {
133  std::unique_ptr<te::da::DataSet> dataSet = GetDataSet();
134 
135  dataSet->moveBeforeFirst();
136 
137  BOOST_CHECK(dataSet->isBeforeBegin());
138 
139  while(dataSet->moveNext())
140  {
141  BOOST_CHECK(dataSet->isPositionValid());
142  }
143 }
144 
145 BOOST_AUTO_TEST_CASE( movePrevious_test )
146 {
147  std::unique_ptr<te::da::DataSet> dataSet = GetDataSet();
148 
149  dataSet->moveLast();
150 
151  BOOST_CHECK(dataSet->isAtEnd());
152 
153  do
154  {
155  BOOST_CHECK(dataSet->isPositionValid());
156  }while(dataSet->movePrevious());
157 }
158 
159 BOOST_AUTO_TEST_SUITE_END()
160 
This file contains include headers for the Data Type module of TerraLib.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
BOOST_AUTO_TEST_CASE(moveFirst_test)
boost::shared_ptr< DataSource > DataSourcePtr
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
A Transactor can be viewed as a connection to the data source for reading/writing things into it...
A factory for data sources.
Geometric property.
Utility functions for the data access module.
std::unique_ptr< te::da::DataSet > GetDataSet()
Implementation of a DataSet for OGR data provider.
BOOST_AUTO_TEST_SUITE(dataSet_tests) BOOST_AUTO_TEST_CASE(moveBeforeFirst_test)