<commit_before>/******************************************************************************
* Copyright (c) 2011, <NAME> (<EMAIL>)
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in
*       the documentation and/or other materials provided
*       with the distribution.
*     * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
*       names of its contributors may be used to endorse or promote
*       products derived from this software without specific prior
*       written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/

#include <boost/test/unit_test.hpp>
#include <boost/cstdint.hpp>
#include <boost/property_tree/ptree.hpp>

#include <pdal/drivers/oci/Reader.hpp>
#include <pdal/drivers/oci/Writer.hpp>
#include <pdal/drivers/oci/common.hpp>

#include <pdal/drivers/las/Reader.hpp>

#include <pdal/filters/CacheFilter.hpp>
#include <pdal/filters/Chipper.hpp>

#include <pdal/drivers/faux/Reader.hpp>
#include <pdal/drivers/faux/Writer.hpp>

#include <pdal/drivers/las/Writer.hpp>
#include <pdal/StageIterator.hpp>

#include "Support.hpp"
#include "TestConfig.hpp"

using namespace pdal;

using namespace pdal::drivers::oci;


bool ShouldRunTest()
{
    return TestConfig::g_oracle_connection.size() > 0;
}

// OptionsOld GetOptions()
// {
//     OptionsOld options;
//     boost::property_tree::ptree& tree = options.GetPTree();
// 
//     tree.put("capacity", 333);
//     tree.put("overwrite", false);
//     tree.put("connection", TestConfig::g_oracle_connection);
//     tree.put("debug", true);
//     tree.put("verbose", true);
//     tree.put("scale.x", 0.0000001);
//     tree.put("scale.y", 0.0000001);
//     tree.put("scale.z", 0.001);
//     tree.put("block_table_name", "PDAL_TEST_BLOCKS");
//     tree.put("base_table_name", "PDAL_TEST_BASE");
//     tree.put("select_sql", "SELECT CLOUD FROM PDAL_TEST_BASE where ID=1");
//     return options;
// }


void RunSQL(Connection connection, std::string sql)
{
    Statement statement = Statement(connection->CreateStatement(sql.c_str()));
    statement->Execute();    
}

BOOST_AUTO_TEST_SUITE(OCITest)




// BOOST_AUTO_TEST_CASE(initialize)
// {
//     if (!ShouldRunTest()) return;
//     
//     Options options = GetOptions();
//     
//     Connection connection = Connect(options);
//     
//     std::string base_table_name = options.GetPTree().get<std::string>("base_table_name");
//     std::string create_pc_table("CREATE TABLE " + base_table_name +" (id number, CLOUD SDO_PC, DESCRIPTION VARCHAR2(20), HEADER BLOB, BOUNDARY SDO_GEOMETRY)");
//     RunSQL(connection, create_pc_table);
//     
//     std::string block_table_name = options.GetPTree().get<std::string>("block_table_name");
//     std::string create_block_table = "CREATE TABLE " + block_table_name + " AS SELECT * FROM MDSYS.SDO_PC_BLK_TABLE";
//     RunSQL(connection, create_block_table);
// }
// 
// 
// BOOST_AUTO_TEST_CASE(test_writer)
// {
//     if (!ShouldRunTest()) return;
// 
//     Options options = GetOptions();
//     pdal::drivers::liblas::LiblasReader reader(Support::datapath("1.2-with-color.las"));
// 
//     boost::uint32_t capacity = GetOptions().GetPTree().get<boost::uint32_t>("capacity");
//     pdal::filters::CacheFilter cache(reader, 1, 1024);
//     pdal::filters::Chipper chipper(cache, capacity);
//     pdal::drivers::oci::Writer writer(chipper, options);
//     
//     BOOST_CHECK_MESSAGE(writer.getConnection().get(), "Unable to connect to Oracle" );
//     
//     writer.write(0);
//     
// }
// 
// BOOST_AUTO_TEST_CASE(test_reader)
// {
//     if (!ShouldRunTest()) return;
// 
//     Options options = GetOptions();
// 
//     pdal::drivers::oci::Reader reader(options);
//     const boost::uint64_t numPoints = reader.getNumPoints();
//     BOOST_CHECK_EQUAL(numPoints, 0);
//     
//     boost::scoped_ptr<SequentialIterator> iter(reader.createSequentialIterator());
//     
//     PointBuffer buffer(reader.getSchema(), 1065);
//     
//     const boost::uint32_t numPointsReadThisChunk = iter->read(buffer);
//     
//     BOOST_CHECK_EQUAL(numPointsReadThisChunk, 1065);
//     // std::ostream* ofs = Utils::createFile("temp.las");
//     // 
//     // pdal::drivers::liblas::LiblasWriter writer(reader, *ofs);
//     // writer.write(0);
//     // 
//     // Utils::closeFile(ofs);
// 
//     
// }


// BOOST_AUTO_TEST_CASE(clean_up)
// {
//     if (!ShouldRunTest()) return;
//     
//     pdal::drivers::oci::Options options = GetOptions();
//     
//     Connection connection = Connect(options);
// 
//     std::string base_table_name = options.GetPTree().get<std::string>("base_table_name");
//     std::string block_table_name = options.GetPTree().get<std::string>("block_table_name");
//     
//     std::string drop_base_table = "DROP TABLE " + base_table_name;
//     std::string drop_block_table = "DROP TABLE " + block_table_name;
//     RunSQL(connection, drop_base_table);
//     RunSQL(connection, drop_block_table);    
// }

BOOST_AUTO_TEST_SUITE_END()<commit_msg>start to revive the oracle test<commit_after>/******************************************************************************
* Copyright (c) 2011, <NAME> (<EMAIL>)
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in
*       the documentation and/or other materials provided
*       with the distribution.
*     * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
*       names of its contributors may be used to endorse or promote
*       products derived from this software without specific prior
*       written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/

#include <boost/test/unit_test.hpp>
#include <boost/cstdint.hpp>
#include <boost/property_tree/ptree.hpp>

#include <pdal/drivers/oci/Reader.hpp>
#include <pdal/drivers/oci/Writer.hpp>
#include <pdal/drivers/oci/common.hpp>

#include <pdal/drivers/las/Reader.hpp>

#include <pdal/filters/CacheFilter.hpp>
#include <pdal/filters/Chipper.hpp>

#include <pdal/drivers/faux/Reader.hpp>
#include <pdal/drivers/faux/Writer.hpp>

#include <pdal/drivers/las/Writer.hpp>
#include <pdal/StageIterator.hpp>

#include "Support.hpp"
#include "TestConfig.hpp"

using namespace pdal;

// using namespace pdal::drivers::oci;


bool ShouldRunTest()
{
    return TestConfig::g_oracle_connection.size() > 0;
}

Options GetOptions()
{
    Options options;
    
    Option capacity("capacity", 333,"capacity");
    options.add(capacity);
    
    Option overwrite("overwrite", false,"overwrite");
    options.add(overwrite);
    
    Option connection("connection",TestConfig::g_oracle_connection, "connection");
    options.add(connection);
    
    Option debug("debug", true, "debug");
    options.add(debug);
    
    Option verbose("verbose", 1, "verbose");
    options.add(verbose);
    
    Option block_table_name("block_table_name", "PDAL_TEST_BLOCKS", "block_table_name");
    options.add(block_table_name);
    
    Option base_table_name("base_table_name", "PDAL_TEST_BASE" , "");
    options.add(base_table_name);
    
    Option cloud_column_name("cloud_column_name", "CLOUD" , "");
    options.add(cloud_column_name);
    
    Option is3d("is3d", false,"");
    options.add(is3d);
    
    Option solid("solid", false,"");
    options.add(solid);
    
    Option srid("srid",4269,"");
    options.add(srid);
    
    Option out_srs("out_srs", "EPSG:4269","");
    options.add(out_srs);

    Option scale_x("scale_x", 0.0000001, "");
    options.add(scale_x);
    
    Option scale_y("scale_y", 0.0000001, "");
    options.add(scale_y);
    
    Option max_cache_blocks("max_cache_blocks", 1, "");
    options.add(max_cache_blocks);
    
    Option cache_block_size("cache_block_size", capacity.getValue<boost::uint32_t>(), "");
    options.add(cache_block_size);
    
    Option filename("filename", Support::datapath("1.2-with-color.las"), "");
    options.add(filename);
    
    Option query("query", "SELECT CLOUD FROM PDAL_TEST_BASE where ID=1", "");
    options.add(query);
    
    return options;
}


void RunSQL(pdal::drivers::oci::Connection connection, std::string sql)
{
    pdal::drivers::oci::Statement statement = pdal::drivers::oci::Statement(connection->CreateStatement(sql.c_str()));
    statement->Execute();    
}

BOOST_AUTO_TEST_SUITE(OCITest)




BOOST_AUTO_TEST_CASE(initialize)
{
    if (!ShouldRunTest()) return;
    
    Options options = GetOptions();
    
    pdal::drivers::oci::Connection connection = pdal::drivers::oci::Connect(options, 
                                                options.getValueOrThrow<bool>("debug"),
                                                options.getValueOrThrow<boost::uint32_t>("verbose"));
    
    std::string base_table_name = options.getValueOrThrow<std::string>("base_table_name");
    std::string create_pc_table("CREATE TABLE " + base_table_name +" (id number, CLOUD SDO_PC, DESCRIPTION VARCHAR2(20), HEADER BLOB, BOUNDARY SDO_GEOMETRY)");
    RunSQL(connection, create_pc_table);
    
    std::string block_table_name = options.getValueOrThrow<std::string>("block_table_name");
    std::string create_block_table = "CREATE TABLE " + block_table_name + " AS SELECT * FROM MDSYS.SDO_PC_BLK_TABLE";
    RunSQL(connection, create_block_table);
}
// 
// 
// BOOST_AUTO_TEST_CASE(test_writer)
// {
//     if (!ShouldRunTest()) return;
// 
//     Options options = GetOptions();
//     pdal::drivers::liblas::LiblasReader reader(Support::datapath("1.2-with-color.las"));
// 
//     boost::uint32_t capacity = GetOptions().GetPTree().get<boost::uint32_t>("capacity");
//     pdal::filters::CacheFilter cache(reader, 1, 1024);
//     pdal::filters::Chipper chipper(cache, capacity);
//     pdal::drivers::oci::Writer writer(chipper, options);
//     
//     BOOST_CHECK_MESSAGE(writer.getConnection().get(), "Unable to connect to Oracle" );
//     
//     writer.write(0);
//     
// }
// 
// BOOST_AUTO_TEST_CASE(test_reader)
// {
//     if (!ShouldRunTest()) return;
// 
//     Options options = GetOptions();
// 
//     pdal::drivers::oci::Reader reader(options);
//     const boost::uint64_t numPoints = reader.getNumPoints();
//     BOOST_CHECK_EQUAL(numPoints, 0);
//     
//     boost::scoped_ptr<SequentialIterator> iter(reader.createSequentialIterator());
//     
//     PointBuffer buffer(reader.getSchema(), 1065);
//     
//     const boost::uint32_t numPointsReadThisChunk = iter->read(buffer);
//     
//     BOOST_CHECK_EQUAL(numPointsReadThisChunk, 1065);
//     // std::ostream* ofs = Utils::createFile("temp.las");
//     // 
//     // pdal::drivers::liblas::LiblasWriter writer(reader, *ofs);
//     // writer.write(0);
//     // 
//     // Utils::closeFile(ofs);
// 
//     
// }


BOOST_AUTO_TEST_CASE(clean_up)
{
    if (!ShouldRunTest()) return;
    
    Options options = GetOptions();
    
    pdal::drivers::oci::Connection connection = pdal::drivers::oci::Connect(options, 
                                                options.getValueOrThrow<bool>("debug"),
                                                options.getValueOrThrow<boost::uint32_t>("verbose"));

    std::string base_table_name = options.getValueOrThrow<std::string>("base_table_name");
    std::string block_table_name = options.getValueOrThrow<std::string>("block_table_name");
    
    std::string drop_base_table = "DROP TABLE " + base_table_name;
    std::string drop_block_table = "DROP TABLE " + block_table_name;
    RunSQL(connection, drop_base_table);
    RunSQL(connection, drop_block_table);    
}

BOOST_AUTO_TEST_SUITE_END()
{'fraction_non_alphanumeric': 0.15876318243776455, 'fraction_numerical': 0.009541574001004376, 'mean_word_length': 3.6497665110073383, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6235890', 'n_tokens_mistral': 4445, 'n_tokens_neox': 4201, 'n_words': 955}