<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: chartonum.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 09:24:43 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_i18npool.hxx"

#define TRANSLITERATION_ALL
#include <chartonum.hxx>
#include <data/numberchar.h>
#include <rtl/ustrbuf.hxx>

using namespace com::sun::star::uno;
using namespace rtl;

namespace com { namespace sun { namespace star { namespace i18n {

#define TRANSLITERATION_CHARTONUM( name ) \
CharToNum##name::CharToNum##name() \
{ \
        nNativeNumberMode = 0; \
        tableSize = 0; \
        implementationName = "com.sun.star.i18n.Transliteration.CharToNum"#name; \
}
TRANSLITERATION_CHARTONUM( Fullwidth)
TRANSLITERATION_CHARTONUM( Lower_zh_CN)
TRANSLITERATION_CHARTONUM( Lower_zh_TW)
TRANSLITERATION_CHARTONUM( Upper_zh_CN)
TRANSLITERATION_CHARTONUM( Upper_zh_TW)
TRANSLITERATION_CHARTONUM( KanjiShort_ja_JP)
TRANSLITERATION_CHARTONUM( KanjiTraditional_ja_JP)
TRANSLITERATION_CHARTONUM( Lower_ko)
TRANSLITERATION_CHARTONUM( Upper_ko)
TRANSLITERATION_CHARTONUM( Hangul_ko)
TRANSLITERATION_CHARTONUM( Indic_ar)
TRANSLITERATION_CHARTONUM( EastIndic_ar)
TRANSLITERATION_CHARTONUM( Indic_hi)
TRANSLITERATION_CHARTONUM( _th)
#undef TRANSLITERATION_CHARTONUM

} } } }
<commit_msg>INTEGRATION: CWS changefileheader (1.6.138); FILE MERGED 2008/03/31 16:01:30 rt 1.6.138.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: chartonum.cxx,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_i18npool.hxx"

#define TRANSLITERATION_ALL
#include <chartonum.hxx>
#include <data/numberchar.h>
#include <rtl/ustrbuf.hxx>

using namespace com::sun::star::uno;
using namespace rtl;

namespace com { namespace sun { namespace star { namespace i18n {

#define TRANSLITERATION_CHARTONUM( name ) \
CharToNum##name::CharToNum##name() \
{ \
        nNativeNumberMode = 0; \
        tableSize = 0; \
        implementationName = "com.sun.star.i18n.Transliteration.CharToNum"#name; \
}
TRANSLITERATION_CHARTONUM( Fullwidth)
TRANSLITERATION_CHARTONUM( Lower_zh_CN)
TRANSLITERATION_CHARTONUM( Lower_zh_TW)
TRANSLITERATION_CHARTONUM( Upper_zh_CN)
TRANSLITERATION_CHARTONUM( Upper_zh_TW)
TRANSLITERATION_CHARTONUM( KanjiShort_ja_JP)
TRANSLITERATION_CHARTONUM( KanjiTraditional_ja_JP)
TRANSLITERATION_CHARTONUM( Lower_ko)
TRANSLITERATION_CHARTONUM( Upper_ko)
TRANSLITERATION_CHARTONUM( Hangul_ko)
TRANSLITERATION_CHARTONUM( Indic_ar)
TRANSLITERATION_CHARTONUM( EastIndic_ar)
TRANSLITERATION_CHARTONUM( Indic_hi)
TRANSLITERATION_CHARTONUM( _th)
#undef TRANSLITERATION_CHARTONUM

} } } }
<|endoftext|>


<commit_before>/* Copyright 2017 R. Thomas
 * Copyright 2017 Quarkslab
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO.hpp"
#include "Object.tcc"

namespace LIEF {
namespace MachO {

Hash::~Hash(void) = default;

size_t Hash::hash(const Object& obj) {
  return LIEF::Hash::hash<LIEF::MachO::Hash>(obj);
}

void Hash::visit(const Binary& binary) {
  this->process(binary.header());
  this->process(std::begin(binary.commands()), std::end(binary.commands()));
  this->process(std::begin(binary.symbols()), std::end(binary.symbols()));
}

void Hash::visit(const Header& header) {
  this->process(header.magic());
  this->process(header.cpu_type());
  this->process(header.cpu_subtype());
  this->process(header.file_type());
  this->process(header.nb_cmds());
  this->process(header.sizeof_cmds());
  this->process(header.flags());
  this->process(header.reserved());
}

void Hash::visit(const LoadCommand& cmd) {
  this->process(cmd.command());
  this->process(cmd.size());
  this->process(cmd.data());
  this->process(cmd.command_offset());
}

void Hash::visit(const UUIDCommand& uuid) {
  this->visit(*uuid.as<LoadCommand>());
  this->process(uuid.uuid());
}

void Hash::visit(const SymbolCommand& symbol) {

  this->visit(*symbol.as<LoadCommand>());
  this->process(symbol.symbol_offset());
  this->process(symbol.numberof_symbols());
  this->process(symbol.strings_offset());
  this->process(symbol.strings_size());
}

void Hash::visit(const SegmentCommand& segment) {

  this->visit(*segment.as<LoadCommand>());
  this->process(segment.name());
  this->process(segment.virtual_address());
  this->process(segment.virtual_size());
  this->process(segment.file_size());
  this->process(segment.file_offset());
  this->process(segment.max_protection());
  this->process(segment.init_protection());
  this->process(segment.numberof_sections());
  this->process(segment.flags());
  this->process(segment.content());
  this->process(std::begin(segment.sections()), std::end(segment.sections()));
}

void Hash::visit(const Section& section) {
  this->visit(*section.as<LoadCommand>());

  this->process(section.content());
  this->process(section.segment_name());
  this->process(section.address());
  this->process(section.alignment());
  this->process(section.relocation_offset());
  this->process(section.numberof_relocations());
  this->process(section.flags());
  this->process(section.type());
  this->process(section.reserved1());
  this->process(section.reserved2());
  this->process(section.reserved3());
  this->process(section.raw_flags());
  this->process(std::begin(section.relocations()), std::end(section.relocations()));
}

void Hash::visit(const MainCommand& maincmd) {

  this->visit(*maincmd.as<LoadCommand>());

  this->process(maincmd.entrypoint());
  this->process(maincmd.stack_size());
}

void Hash::visit(const DynamicSymbolCommand& dynamic_symbol) {
  this->visit(*dynamic_symbol.as<LoadCommand>());
  this->process(dynamic_symbol.idx_local_symbol());
  this->process(dynamic_symbol.nb_local_symbols());

  this->process(dynamic_symbol.idx_external_define_symbol());
  this->process(dynamic_symbol.nb_external_define_symbols());

  this->process(dynamic_symbol.idx_undefined_symbol());
  this->process(dynamic_symbol.nb_undefined_symbols());

  this->process(dynamic_symbol.toc_offset());
  this->process(dynamic_symbol.nb_toc());

  this->process(dynamic_symbol.module_table_offset());
  this->process(dynamic_symbol.nb_module_table());

  this->process(dynamic_symbol.external_reference_symbol_offset());
  this->process(dynamic_symbol.nb_external_reference_symbols());

  this->process(dynamic_symbol.indirect_symbol_offset());
  this->process(dynamic_symbol.nb_indirect_symbols());

  this->process(dynamic_symbol.external_relocation_offset());
  this->process(dynamic_symbol.nb_external_relocations());

  this->process(dynamic_symbol.local_relocation_offset());
  this->process(dynamic_symbol.nb_local_relocations());
}

void Hash::visit(const DylinkerCommand& dylinker) {
  this->visit(*dylinker.as<LoadCommand>());
  this->process(dylinker.name());
}

void Hash::visit(const DylibCommand& dylib) {
  this->visit(*dylib.as<LoadCommand>());

  this->process(dylib.name());
  this->process(dylib.timestamp());
  this->process(dylib.current_version());
  this->process(dylib.compatibility_version());
}

void Hash::visit(const ThreadCommand& threadcmd) {
  this->visit(*threadcmd.as<LoadCommand>());
  this->process(threadcmd.flavor());
  this->process(threadcmd.count());
  this->process(threadcmd.state());
}

void Hash::visit(const RPathCommand& rpath) {
  this->visit(*rpath.as<LoadCommand>());
  this->process(rpath.path());
}

void Hash::visit(const Symbol& symbol) {
  this->process(symbol.name());
  this->process(symbol.type());
  this->process(symbol.numberof_sections());
  this->process(symbol.description());
  this->process(symbol.value());

  if (symbol.has_binding_info()) {
    this->process(symbol.binding_info());
  }

  if (symbol.has_export_info()) {
    this->process(symbol.export_info());
  }
}

void Hash::visit(const Relocation& relocation) {

  this->process(relocation.size());
  this->process(relocation.address());
  this->process(relocation.is_pc_relative());
  this->process(relocation.type());
  this->process(relocation.origin());

  if (relocation.has_symbol()) {
    this->process(relocation.symbol().name());
  }
}

void Hash::visit(const RelocationObject& robject) {

  this->visit(*robject.as<Relocation>());
  this->process(robject.is_scattered());
  if (robject.is_scattered()) {
    this->process(robject.value());
  }
}

void Hash::visit(const RelocationDyld& rdyld) {
  this->visit(*rdyld.as<Relocation>());
}

void Hash::visit(const BindingInfo& binding) {

  this->process(binding.binding_class());
  this->process(binding.binding_type());
  this->process(binding.library_ordinal());
  this->process(binding.addend());
  this->process(binding.is_weak_import());
  this->process(binding.address());

  if (binding.has_symbol()) {
    this->process(binding.symbol().name());
  }

  if (binding.has_library()) {
    this->process(binding.library());
  }
}

void Hash::visit(const ExportInfo& einfo) {
  this->process(einfo.node_offset());
  this->process(einfo.flags());
  this->process(einfo.address());

  if (einfo.has_symbol()) {
    this->process(einfo.symbol().name());
  }
}

void Hash::visit(const FunctionStarts& fs) {
  this->visit(*fs.as<LoadCommand>());
  this->process(fs.data_offset());
  this->process(fs.data_size());
  this->process(fs.functions());

}

void Hash::visit(const CodeSignature& cs) {
  this->visit(*cs.as<LoadCommand>());
  this->process(cs.data_offset());
  this->process(cs.data_size());
}

void Hash::visit(const DataInCode& dic) {
  this->visit(*dic.as<LoadCommand>());
  this->process(dic.data_offset());
  this->process(dic.data_size());
  this->process(std::begin(dic.entries()), std::end(dic.entries()));
}

void Hash::visit(const DataCodeEntry& dce) {
  this->process(dce.offset());
  this->process(dce.length());
  this->process(dce.type());
}

void Hash::visit(const VersionMin& vmin) {
  this->visit(*vmin.as<LoadCommand>());
  this->process(vmin.version());
  this->process(vmin.sdk());
}

void Hash::visit(const SourceVersion& sv) {
  this->visit(*sv.as<LoadCommand>());
  this->process(sv.version());
}

void Hash::visit(const SegmentSplitInfo& ssi) {
  this->visit(*ssi.as<LoadCommand>());
  this->process(ssi.data_offset());
  this->process(ssi.data_size());
}

void Hash::visit(const SubFramework& sf) {
  this->visit(*sf.as<LoadCommand>());
  this->process(sf.umbrella());
}

void Hash::visit(const DyldEnvironment& de) {
  this->visit(*de.as<LoadCommand>());
  this->process(de.value());
}

void Hash::visit(const EncryptionInfo& e) {
  this->visit(*e.as<LoadCommand>());
  this->process(e.crypt_offset());
  this->process(e.crypt_size());
  this->process(e.crypt_id());
}

} // namespace MachO
} // namespace LIEF

<commit_msg>Bug Fix: Mach-O Section is not a load command<commit_after>/* Copyright 2017 R. Thomas
 * Copyright 2017 Quarkslab
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO.hpp"
#include "Object.tcc"

namespace LIEF {
namespace MachO {

Hash::~Hash(void) = default;

size_t Hash::hash(const Object& obj) {
  return LIEF::Hash::hash<LIEF::MachO::Hash>(obj);
}

void Hash::visit(const Binary& binary) {
  this->process(binary.header());
  this->process(std::begin(binary.commands()), std::end(binary.commands()));
  this->process(std::begin(binary.symbols()), std::end(binary.symbols()));
}

void Hash::visit(const Header& header) {
  this->process(header.magic());
  this->process(header.cpu_type());
  this->process(header.cpu_subtype());
  this->process(header.file_type());
  this->process(header.nb_cmds());
  this->process(header.sizeof_cmds());
  this->process(header.flags());
  this->process(header.reserved());
}

void Hash::visit(const LoadCommand& cmd) {
  this->process(cmd.command());
  this->process(cmd.size());
  this->process(cmd.data());
  this->process(cmd.command_offset());
}

void Hash::visit(const UUIDCommand& uuid) {
  this->visit(*uuid.as<LoadCommand>());
  this->process(uuid.uuid());
}

void Hash::visit(const SymbolCommand& symbol) {

  this->visit(*symbol.as<LoadCommand>());
  this->process(symbol.symbol_offset());
  this->process(symbol.numberof_symbols());
  this->process(symbol.strings_offset());
  this->process(symbol.strings_size());
}

void Hash::visit(const SegmentCommand& segment) {

  this->visit(*segment.as<LoadCommand>());
  this->process(segment.name());
  this->process(segment.virtual_address());
  this->process(segment.virtual_size());
  this->process(segment.file_size());
  this->process(segment.file_offset());
  this->process(segment.max_protection());
  this->process(segment.init_protection());
  this->process(segment.numberof_sections());
  this->process(segment.flags());
  this->process(segment.content());
  this->process(std::begin(segment.sections()), std::end(segment.sections()));
}

void Hash::visit(const Section& section) {
  this->process(section.content());
  this->process(section.segment_name());
  this->process(section.address());
  this->process(section.alignment());
  this->process(section.relocation_offset());
  this->process(section.numberof_relocations());
  this->process(section.flags());
  this->process(section.type());
  this->process(section.reserved1());
  this->process(section.reserved2());
  this->process(section.reserved3());
  this->process(section.raw_flags());
  this->process(std::begin(section.relocations()), std::end(section.relocations()));
}

void Hash::visit(const MainCommand& maincmd) {

  this->visit(*maincmd.as<LoadCommand>());

  this->process(maincmd.entrypoint());
  this->process(maincmd.stack_size());
}

void Hash::visit(const DynamicSymbolCommand& dynamic_symbol) {
  this->visit(*dynamic_symbol.as<LoadCommand>());
  this->process(dynamic_symbol.idx_local_symbol());
  this->process(dynamic_symbol.nb_local_symbols());

  this->process(dynamic_symbol.idx_external_define_symbol());
  this->process(dynamic_symbol.nb_external_define_symbols());

  this->process(dynamic_symbol.idx_undefined_symbol());
  this->process(dynamic_symbol.nb_undefined_symbols());

  this->process(dynamic_symbol.toc_offset());
  this->process(dynamic_symbol.nb_toc());

  this->process(dynamic_symbol.module_table_offset());
  this->process(dynamic_symbol.nb_module_table());

  this->process(dynamic_symbol.external_reference_symbol_offset());
  this->process(dynamic_symbol.nb_external_reference_symbols());

  this->process(dynamic_symbol.indirect_symbol_offset());
  this->process(dynamic_symbol.nb_indirect_symbols());

  this->process(dynamic_symbol.external_relocation_offset());
  this->process(dynamic_symbol.nb_external_relocations());

  this->process(dynamic_symbol.local_relocation_offset());
  this->process(dynamic_symbol.nb_local_relocations());
}

void Hash::visit(const DylinkerCommand& dylinker) {
  this->visit(*dylinker.as<LoadCommand>());
  this->process(dylinker.name());
}

void Hash::visit(const DylibCommand& dylib) {
  this->visit(*dylib.as<LoadCommand>());

  this->process(dylib.name());
  this->process(dylib.timestamp());
  this->process(dylib.current_version());
  this->process(dylib.compatibility_version());
}

void Hash::visit(const ThreadCommand& threadcmd) {
  this->visit(*threadcmd.as<LoadCommand>());
  this->process(threadcmd.flavor());
  this->process(threadcmd.count());
  this->process(threadcmd.state());
}

void Hash::visit(const RPathCommand& rpath) {
  this->visit(*rpath.as<LoadCommand>());
  this->process(rpath.path());
}

void Hash::visit(const Symbol& symbol) {
  this->process(symbol.name());
  this->process(symbol.type());
  this->process(symbol.numberof_sections());
  this->process(symbol.description());
  this->process(symbol.value());

  if (symbol.has_binding_info()) {
    this->process(symbol.binding_info());
  }

  if (symbol.has_export_info()) {
    this->process(symbol.export_info());
  }
}

void Hash::visit(const Relocation& relocation) {

  this->process(relocation.size());
  this->process(relocation.address());
  this->process(relocation.is_pc_relative());
  this->process(relocation.type());
  this->process(relocation.origin());

  if (relocation.has_symbol()) {
    this->process(relocation.symbol().name());
  }
}

void Hash::visit(const RelocationObject& robject) {

  this->visit(*robject.as<Relocation>());
  this->process(robject.is_scattered());
  if (robject.is_scattered()) {
    this->process(robject.value());
  }
}

void Hash::visit(const RelocationDyld& rdyld) {
  this->visit(*rdyld.as<Relocation>());
}

void Hash::visit(const BindingInfo& binding) {

  this->process(binding.binding_class());
  this->process(binding.binding_type());
  this->process(binding.library_ordinal());
  this->process(binding.addend());
  this->process(binding.is_weak_import());
  this->process(binding.address());

  if (binding.has_symbol()) {
    this->process(binding.symbol().name());
  }

  if (binding.has_library()) {
    this->process(binding.library());
  }
}

void Hash::visit(const ExportInfo& einfo) {
  this->process(einfo.node_offset());
  this->process(einfo.flags());
  this->process(einfo.address());

  if (einfo.has_symbol()) {
    this->process(einfo.symbol().name());
  }
}

void Hash::visit(const FunctionStarts& fs) {
  this->visit(*fs.as<LoadCommand>());
  this->process(fs.data_offset());
  this->process(fs.data_size());
  this->process(fs.functions());

}

void Hash::visit(const CodeSignature& cs) {
  this->visit(*cs.as<LoadCommand>());
  this->process(cs.data_offset());
  this->process(cs.data_size());
}

void Hash::visit(const DataInCode& dic) {
  this->visit(*dic.as<LoadCommand>());
  this->process(dic.data_offset());
  this->process(dic.data_size());
  this->process(std::begin(dic.entries()), std::end(dic.entries()));
}

void Hash::visit(const DataCodeEntry& dce) {
  this->process(dce.offset());
  this->process(dce.length());
  this->process(dce.type());
}

void Hash::visit(const VersionMin& vmin) {
  this->visit(*vmin.as<LoadCommand>());
  this->process(vmin.version());
  this->process(vmin.sdk());
}

void Hash::visit(const SourceVersion& sv) {
  this->visit(*sv.as<LoadCommand>());
  this->process(sv.version());
}

void Hash::visit(const SegmentSplitInfo& ssi) {
  this->visit(*ssi.as<LoadCommand>());
  this->process(ssi.data_offset());
  this->process(ssi.data_size());
}

void Hash::visit(const SubFramework& sf) {
  this->visit(*sf.as<LoadCommand>());
  this->process(sf.umbrella());
}

void Hash::visit(const DyldEnvironment& de) {
  this->visit(*de.as<LoadCommand>());
  this->process(de.value());
}

void Hash::visit(const EncryptionInfo& e) {
  this->visit(*e.as<LoadCommand>());
  this->process(e.crypt_offset());
  this->process(e.crypt_size());
  this->process(e.crypt_id());
}

} // namespace MachO
} // namespace LIEF

<|endoftext|>


<commit_before>#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#include "phpcxx/module.h"
#include "phpcxx/constant.h"
#include "testsapi.h"

extern "C" {
#include <Zend/zend.h>
#include <Zend/zend_constants.h>
}

namespace {

class MyModule : public phpcxx::Module {
public:
    using phpcxx::Module::Module;

protected:
    virtual std::vector<phpcxx::Constant> constants()
    {
        phpcxx::Constant bool_const("BOOL_CONST", true);
        phpcxx::Constant int_const("INT_CONST", 10);
        phpcxx::Constant long_const("LONG_CONST", static_cast<zend_long>(100));
        phpcxx::Constant double_const("DOUBLE_CONST", 200.0);
        phpcxx::Constant float_const("FLOAT_CONST", 300.0f);
        phpcxx::Constant null_const("NULL_CONST");
        phpcxx::Constant string_const("STRING_CONST", "string");
        phpcxx::Constant string_const2("STRING_CONST2", std::string("std::string"));

        phpcxx::Constant not_used("NOT_USED_CONSTANT", "if a constant is not registered, it should not cause a memory leak");
        phpcxx::Constant duplicate("STRING_CONST", "a duplicate constant should not cause memory leak");

        return { bool_const, int_const, long_const, double_const, float_const, null_const, string_const, string_const2, duplicate };
    }
};

class MyModule2 : public phpcxx::Module {
public:
    using phpcxx::Module::Module;

protected:
    virtual bool moduleStartup() override
    {
        phpcxx::Constant bool_const("BOOL_CONST", true);
        phpcxx::Constant int_const("INT_CONST", 10);
        phpcxx::Constant long_const("LONG_CONST", static_cast<zend_long>(100));
        phpcxx::Constant double_const("DOUBLE_CONST", 200.0);
        phpcxx::Constant float_const("FLOAT_CONST", 300.0f);
        phpcxx::Constant null_const("NULL_CONST");
        phpcxx::Constant string_const("STRING_CONST", "string");
        phpcxx::Constant string_const2("STRING_CONST2", std::string("std::string"));

        phpcxx::Constant not_used("NOT_USED_CONSTANT", "if a constant is not registered, it should not cause a memory leak");
        phpcxx::Constant duplicate("STRING_CONST", "a duplicate constant should not cause memory leak");

        EXPECT_TRUE(bool_const.registerConstant());
        EXPECT_TRUE(int_const.registerConstant());
        EXPECT_TRUE(long_const.registerConstant());
        EXPECT_TRUE(double_const.registerConstant());
        EXPECT_TRUE(float_const.registerConstant());
        EXPECT_TRUE(null_const.registerConstant());
        EXPECT_TRUE(string_const.registerConstant());
        EXPECT_TRUE(string_const2.registerConstant());
        EXPECT_FALSE(duplicate.registerConstant());

        return true;
    }
};

}

TEST(ConstantsTest, TestConstants)
{
    MyModule module("Constants", "0.0");

    std::stringstream out;
    std::stringstream err;

    {
        TestSAPI sapi(out, err);
        sapi.addModule(module);
        sapi.initialize();

        std::string o = out.str(); out.str("");
        std::string e = err.str(); err.str("");
        EXPECT_NE(std::string::npos, e.find("Constant STRING_CONST already defined"));
        EXPECT_EQ("", o);

        zval* bc  = zend_get_constant_str(ZEND_STRL("BOOL_CONST"));
        zval* ic  = zend_get_constant_str(ZEND_STRL("INT_CONST"));
        zval* lc  = zend_get_constant_str(ZEND_STRL("LONG_CONST"));
        zval* dc  = zend_get_constant_str(ZEND_STRL("DOUBLE_CONST"));
        zval* fc  = zend_get_constant_str(ZEND_STRL("FLOAT_CONST"));
        zval* nc  = zend_get_constant_str(ZEND_STRL("NULL_CONST"));
        zval* sc1 = zend_get_constant_str(ZEND_STRL("STRING_CONST"));
        zval* sc2 = zend_get_constant_str(ZEND_STRL("STRING_CONST2"));
        zval* uc  = zend_get_constant_str(ZEND_STRL("NOT_USED_CONSTANT"));

        ASSERT_TRUE(bc  != nullptr);
        ASSERT_TRUE(ic  != nullptr);
        ASSERT_TRUE(lc  != nullptr);
        ASSERT_TRUE(dc  != nullptr);
        ASSERT_TRUE(fc  != nullptr);
        ASSERT_TRUE(nc  != nullptr);
        ASSERT_TRUE(sc1 != nullptr);
        ASSERT_TRUE(sc2 != nullptr);
        EXPECT_EQ(uc, nullptr);

        EXPECT_EQ(IS_TRUE,   Z_TYPE_P(bc));

        EXPECT_EQ(IS_LONG,   Z_TYPE_P(ic));
        EXPECT_EQ(IS_LONG,   Z_TYPE_P(lc));
        EXPECT_EQ(10,        Z_LVAL_P(ic));
        EXPECT_EQ(100,       Z_LVAL_P(lc));

        EXPECT_EQ(IS_DOUBLE, Z_TYPE_P(dc));
        EXPECT_EQ(IS_DOUBLE, Z_TYPE_P(fc));
        EXPECT_EQ(200,       Z_DVAL_P(dc));
        EXPECT_EQ(300,       Z_DVAL_P(fc));

        EXPECT_EQ(IS_NULL,   Z_TYPE_P(nc));

        ASSERT_EQ(IS_STRING, Z_TYPE_P(sc1));
        ASSERT_EQ(IS_STRING, Z_TYPE_P(sc2));

        EXPECT_STREQ("string",      Z_STRVAL_P(sc1));
        EXPECT_STREQ("std::string", Z_STRVAL_P(sc2));

        // Issue #4: if we don't run php_request_startup() and php_request_shutdown() after sapi.initialize()
        // we can get memory corruption in NTS builds
        sapi.run();
    }

    std::string o = out.str(); out.str("");
    std::string e = err.str(); err.str("");
    EXPECT_EQ("", o);
    EXPECT_EQ("", e);
}

TEST(ConstantsTest, TestManualRegistration)
{
    MyModule2 module("Constants", "0.0");

    std::stringstream out;
    std::stringstream err;

    {
        TestSAPI sapi(out, err);
        sapi.addModule(module);
        sapi.initialize();

        phpcxx::Constant false_const("FALSE_CONST", false);
        EXPECT_FALSE(false_const.registerConstant());

        std::string o = out.str(); out.str("");
        std::string e = err.str(); err.str("");
        EXPECT_NE(std::string::npos, e.find("Constant STRING_CONST already defined"));
        EXPECT_EQ("", o);

        zval* bc  = zend_get_constant_str(ZEND_STRL("BOOL_CONST"));
        zval* ic  = zend_get_constant_str(ZEND_STRL("INT_CONST"));
        zval* lc  = zend_get_constant_str(ZEND_STRL("LONG_CONST"));
        zval* dc  = zend_get_constant_str(ZEND_STRL("DOUBLE_CONST"));
        zval* fc  = zend_get_constant_str(ZEND_STRL("FLOAT_CONST"));
        zval* nc  = zend_get_constant_str(ZEND_STRL("NULL_CONST"));
        zval* sc1 = zend_get_constant_str(ZEND_STRL("STRING_CONST"));
        zval* sc2 = zend_get_constant_str(ZEND_STRL("STRING_CONST2"));
        zval* uc  = zend_get_constant_str(ZEND_STRL("NOT_USED_CONSTANT"));

        ASSERT_TRUE(bc  != nullptr);
        ASSERT_TRUE(ic  != nullptr);
        ASSERT_TRUE(lc  != nullptr);
        ASSERT_TRUE(dc  != nullptr);
        ASSERT_TRUE(fc  != nullptr);
        ASSERT_TRUE(nc  != nullptr);
        ASSERT_TRUE(sc1 != nullptr);
        ASSERT_TRUE(sc2 != nullptr);
        EXPECT_EQ(uc, nullptr);

        EXPECT_EQ(IS_TRUE,   Z_TYPE_P(bc));

        EXPECT_EQ(IS_LONG,   Z_TYPE_P(ic));
        EXPECT_EQ(IS_LONG,   Z_TYPE_P(lc));
        EXPECT_EQ(10,        Z_LVAL_P(ic));
        EXPECT_EQ(100,       Z_LVAL_P(lc));

        EXPECT_EQ(IS_DOUBLE, Z_TYPE_P(dc));
        EXPECT_EQ(IS_DOUBLE, Z_TYPE_P(fc));
        EXPECT_EQ(200,       Z_DVAL_P(dc));
        EXPECT_EQ(300,       Z_DVAL_P(fc));

        EXPECT_EQ(IS_NULL,   Z_TYPE_P(nc));

        ASSERT_EQ(IS_STRING, Z_TYPE_P(sc1));
        ASSERT_EQ(IS_STRING, Z_TYPE_P(sc2));

        EXPECT_STREQ("string",      Z_STRVAL_P(sc1));
        EXPECT_STREQ("std::string", Z_STRVAL_P(sc2));

        // Issue #4: if we don't run php_request_startup() and php_request_shutdown() after sapi.initialize()
        // we can get memory corruption in NTS builds
        sapi.run();
    }

    std::string o = out.str(); out.str("");
    std::string e = err.str(); err.str("");
    EXPECT_EQ("", o);
    EXPECT_EQ("", e);
}
<commit_msg>Rename tests [ci skip]<commit_after>#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#include "phpcxx/module.h"
#include "phpcxx/constant.h"
#include "testsapi.h"

extern "C" {
#include <Zend/zend.h>
#include <Zend/zend_constants.h>
}

namespace {

class MyModule : public phpcxx::Module {
public:
    using phpcxx::Module::Module;

protected:
    virtual std::vector<phpcxx::Constant> constants()
    {
        phpcxx::Constant bool_const("BOOL_CONST", true);
        phpcxx::Constant int_const("INT_CONST", 10);
        phpcxx::Constant long_const("LONG_CONST", static_cast<zend_long>(100));
        phpcxx::Constant double_const("DOUBLE_CONST", 200.0);
        phpcxx::Constant float_const("FLOAT_CONST", 300.0f);
        phpcxx::Constant null_const("NULL_CONST");
        phpcxx::Constant string_const("STRING_CONST", "string");
        phpcxx::Constant string_const2("STRING_CONST2", std::string("std::string"));

        phpcxx::Constant not_used("NOT_USED_CONSTANT", "if a constant is not registered, it should not cause a memory leak");
        phpcxx::Constant duplicate("STRING_CONST", "a duplicate constant should not cause memory leak");

        return { bool_const, int_const, long_const, double_const, float_const, null_const, string_const, string_const2, duplicate };
    }
};

class MyModule2 : public phpcxx::Module {
public:
    using phpcxx::Module::Module;

protected:
    virtual bool moduleStartup() override
    {
        phpcxx::Constant bool_const("BOOL_CONST", true);
        phpcxx::Constant int_const("INT_CONST", 10);
        phpcxx::Constant long_const("LONG_CONST", static_cast<zend_long>(100));
        phpcxx::Constant double_const("DOUBLE_CONST", 200.0);
        phpcxx::Constant float_const("FLOAT_CONST", 300.0f);
        phpcxx::Constant null_const("NULL_CONST");
        phpcxx::Constant string_const("STRING_CONST", "string");
        phpcxx::Constant string_const2("STRING_CONST2", std::string("std::string"));

        phpcxx::Constant not_used("NOT_USED_CONSTANT", "if a constant is not registered, it should not cause a memory leak");
        phpcxx::Constant duplicate("STRING_CONST", "a duplicate constant should not cause memory leak");

        EXPECT_TRUE(bool_const.registerConstant());
        EXPECT_TRUE(int_const.registerConstant());
        EXPECT_TRUE(long_const.registerConstant());
        EXPECT_TRUE(double_const.registerConstant());
        EXPECT_TRUE(float_const.registerConstant());
        EXPECT_TRUE(null_const.registerConstant());
        EXPECT_TRUE(string_const.registerConstant());
        EXPECT_TRUE(string_const2.registerConstant());
        EXPECT_FALSE(duplicate.registerConstant());

        return true;
    }
};

}

TEST(Constants, TestConstants)
{
    MyModule module("Constants", "0.0");

    std::stringstream out;
    std::stringstream err;

    {
        TestSAPI sapi(out, err);
        sapi.addModule(module);
        sapi.initialize();

        std::string o = out.str(); out.str("");
        std::string e = err.str(); err.str("");
        EXPECT_NE(std::string::npos, e.find("Constant STRING_CONST already defined"));
        EXPECT_EQ("", o);

        zval* bc  = zend_get_constant_str(ZEND_STRL("BOOL_CONST"));
        zval* ic  = zend_get_constant_str(ZEND_STRL("INT_CONST"));
        zval* lc  = zend_get_constant_str(ZEND_STRL("LONG_CONST"));
        zval* dc  = zend_get_constant_str(ZEND_STRL("DOUBLE_CONST"));
        zval* fc  = zend_get_constant_str(ZEND_STRL("FLOAT_CONST"));
        zval* nc  = zend_get_constant_str(ZEND_STRL("NULL_CONST"));
        zval* sc1 = zend_get_constant_str(ZEND_STRL("STRING_CONST"));
        zval* sc2 = zend_get_constant_str(ZEND_STRL("STRING_CONST2"));
        zval* uc  = zend_get_constant_str(ZEND_STRL("NOT_USED_CONSTANT"));

        ASSERT_TRUE(bc  != nullptr);
        ASSERT_TRUE(ic  != nullptr);
        ASSERT_TRUE(lc  != nullptr);
        ASSERT_TRUE(dc  != nullptr);
        ASSERT_TRUE(fc  != nullptr);
        ASSERT_TRUE(nc  != nullptr);
        ASSERT_TRUE(sc1 != nullptr);
        ASSERT_TRUE(sc2 != nullptr);
        EXPECT_EQ(uc, nullptr);

        EXPECT_EQ(IS_TRUE,   Z_TYPE_P(bc));

        EXPECT_EQ(IS_LONG,   Z_TYPE_P(ic));
        EXPECT_EQ(IS_LONG,   Z_TYPE_P(lc));
        EXPECT_EQ(10,        Z_LVAL_P(ic));
        EXPECT_EQ(100,       Z_LVAL_P(lc));

        EXPECT_EQ(IS_DOUBLE, Z_TYPE_P(dc));
        EXPECT_EQ(IS_DOUBLE, Z_TYPE_P(fc));
        EXPECT_EQ(200,       Z_DVAL_P(dc));
        EXPECT_EQ(300,       Z_DVAL_P(fc));

        EXPECT_EQ(IS_NULL,   Z_TYPE_P(nc));

        ASSERT_EQ(IS_STRING, Z_TYPE_P(sc1));
        ASSERT_EQ(IS_STRING, Z_TYPE_P(sc2));

        EXPECT_STREQ("string",      Z_STRVAL_P(sc1));
        EXPECT_STREQ("std::string", Z_STRVAL_P(sc2));

        // Issue #4: if we don't run php_request_startup() and php_request_shutdown() after sapi.initialize()
        // we can get memory corruption in NTS builds
        sapi.run();
    }

    std::string o = out.str(); out.str("");
    std::string e = err.str(); err.str("");
    EXPECT_EQ("", o);
    EXPECT_EQ("", e);
}

TEST(Constants, TestManualRegistration)
{
    MyModule2 module("Constants", "0.0");

    std::stringstream out;
    std::stringstream err;

    {
        TestSAPI sapi(out, err);
        sapi.addModule(module);
        sapi.initialize();

        phpcxx::Constant false_const("FALSE_CONST", false);
        EXPECT_FALSE(false_const.registerConstant());

        std::string o = out.str(); out.str("");
        std::string e = err.str(); err.str("");
        EXPECT_NE(std::string::npos, e.find("Constant STRING_CONST already defined"));
        EXPECT_EQ("", o);

        zval* bc  = zend_get_constant_str(ZEND_STRL("BOOL_CONST"));
        zval* ic  = zend_get_constant_str(ZEND_STRL("INT_CONST"));
        zval* lc  = zend_get_constant_str(ZEND_STRL("LONG_CONST"));
        zval* dc  = zend_get_constant_str(ZEND_STRL("DOUBLE_CONST"));
        zval* fc  = zend_get_constant_str(ZEND_STRL("FLOAT_CONST"));
        zval* nc  = zend_get_constant_str(ZEND_STRL("NULL_CONST"));
        zval* sc1 = zend_get_constant_str(ZEND_STRL("STRING_CONST"));
        zval* sc2 = zend_get_constant_str(ZEND_STRL("STRING_CONST2"));
        zval* uc  = zend_get_constant_str(ZEND_STRL("NOT_USED_CONSTANT"));

        ASSERT_TRUE(bc  != nullptr);
        ASSERT_TRUE(ic  != nullptr);
        ASSERT_TRUE(lc  != nullptr);
        ASSERT_TRUE(dc  != nullptr);
        ASSERT_TRUE(fc  != nullptr);
        ASSERT_TRUE(nc  != nullptr);
        ASSERT_TRUE(sc1 != nullptr);
        ASSERT_TRUE(sc2 != nullptr);
        EXPECT_EQ(uc, nullptr);

        EXPECT_EQ(IS_TRUE,   Z_TYPE_P(bc));

        EXPECT_EQ(IS_LONG,   Z_TYPE_P(ic));
        EXPECT_EQ(IS_LONG,   Z_TYPE_P(lc));
        EXPECT_EQ(10,        Z_LVAL_P(ic));
        EXPECT_EQ(100,       Z_LVAL_P(lc));

        EXPECT_EQ(IS_DOUBLE, Z_TYPE_P(dc));
        EXPECT_EQ(IS_DOUBLE, Z_TYPE_P(fc));
        EXPECT_EQ(200,       Z_DVAL_P(dc));
        EXPECT_EQ(300,       Z_DVAL_P(fc));

        EXPECT_EQ(IS_NULL,   Z_TYPE_P(nc));

        ASSERT_EQ(IS_STRING, Z_TYPE_P(sc1));
        ASSERT_EQ(IS_STRING, Z_TYPE_P(sc2));

        EXPECT_STREQ("string",      Z_STRVAL_P(sc1));
        EXPECT_STREQ("std::string", Z_STRVAL_P(sc2));

        // Issue #4: if we don't run php_request_startup() and php_request_shutdown() after sapi.initialize()
        // we can get memory corruption in NTS builds
        sapi.run();
    }

    std::string o = out.str(); out.str("");
    std::string e = err.str(); err.str("");
    EXPECT_EQ("", o);
    EXPECT_EQ("", e);
}
<|endoftext|>


<commit_before>// RUN: %clang_cc1 -fsyntax-only -verify %s

// <rdar://problem/8124080>
template<typename _Alloc> class allocator;
template<class _CharT> struct char_traits;
template<typename _CharT, typename _Traits = char_traits<_CharT>,
         typename _Alloc = allocator<_CharT> >
class basic_string;
template<typename _CharT, typename _Traits, typename _Alloc>
const typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_max_size // expected-error{{no member named '_Rep' in 'basic_string<_CharT, _Traits, _Alloc>'}}
  = (((npos - sizeof(_Rep_base))/sizeof(_CharT)) - 1) / 4;

// PR7118
template<typename T>
class Foo {
  class Bar;
  void f() {
    Bar i;
  }
};

// PR7625
template<typename T> struct a : T {
 struct x : T {
   int aa() { return p; } // expected-error{{use of undeclared identifier 'p'}}
 };
};

// rdar://8605381
namespace rdar8605381 {
struct X {};

struct Y { // expected-note{{candidate}}
  Y();
};

struct {
  Y obj;
} objs[] = {
  new Y // expected-error{{no viable conversion}}
};
}

// http://llvm.org/PR8234
namespace PR8234 {
template<typename Signature>
class callback
{
};

template<typename R , typename ARG_TYPE0>
class callback<R( ARG_TYPE0)>
{
    public:
        callback() {}
};

template< typename ARG_TYPE0>
class callback<void( ARG_TYPE0)>
{
    public:
        callback() {}
};

void f()
{
    callback<void(const int&)> op;
}
}

namespace PR9007 {
  struct bar {
    enum xxx {
      yyy = sizeof(struct foo*)
    };
    foo *xxx();
  };
}

namespace PR9026 {
  class InfallibleTArray {
  };
  class Variant;
  class CompVariant {
    operator const InfallibleTArray&() const;
  };
  class Variant {
    operator const CompVariant&() const;
  };
  void     Write(const Variant& __v);
  void     Write(const InfallibleTArray& __v);
  Variant x;
  void Write2() {
    Write(x);
  }
}

namespace PR10270 {
  template<typename T> class C;
  template<typename T> void f() {
    if (C<T> == 1) // expected-error{{expected unqualified-id}} \
                   // expected-error{{invalid '==' at end of declaration}}
      return;
  }
}

namespace rdar11806334 {

class cc_YCbCr;

class cc_rgb
{
 public:
  cc_rgb( uint p ); // expected-error {{unknown type name}}
  cc_rgb( cc_YCbCr v_in );
};

class cc_hsl
{
 public:
  cc_rgb rgb();
  cc_YCbCr YCbCr();
};

class cc_YCbCr
{
 public:
  cc_YCbCr( const cc_rgb v_in );
};

cc_YCbCr cc_hsl::YCbCr()
{
 cc_YCbCr v_out = cc_YCbCr( rgb());
 return v_out;
}

}

namespace test1 {
  int getString(const int*);
  template<int a> class ELFObjectFile  {
    const int* sh;
    ELFObjectFile() {
      switch (*sh) {
      }
      int SectionName(getString(sh));
    }
  };
}
<commit_msg>Add a testcase from the previous bootstrap problem.<commit_after>// RUN: %clang_cc1 -fsyntax-only -verify %s

// <rdar://problem/8124080>
template<typename _Alloc> class allocator;
template<class _CharT> struct char_traits;
template<typename _CharT, typename _Traits = char_traits<_CharT>,
         typename _Alloc = allocator<_CharT> >
class basic_string;
template<typename _CharT, typename _Traits, typename _Alloc>
const typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_max_size // expected-error{{no member named '_Rep' in 'basic_string<_CharT, _Traits, _Alloc>'}}
  = (((npos - sizeof(_Rep_base))/sizeof(_CharT)) - 1) / 4;

// PR7118
template<typename T>
class Foo {
  class Bar;
  void f() {
    Bar i;
  }
};

// PR7625
template<typename T> struct a : T {
 struct x : T {
   int aa() { return p; } // expected-error{{use of undeclared identifier 'p'}}
 };
};

// rdar://8605381
namespace rdar8605381 {
struct X {};

struct Y { // expected-note{{candidate}}
  Y();
};

struct {
  Y obj;
} objs[] = {
  new Y // expected-error{{no viable conversion}}
};
}

// http://llvm.org/PR8234
namespace PR8234 {
template<typename Signature>
class callback
{
};

template<typename R , typename ARG_TYPE0>
class callback<R( ARG_TYPE0)>
{
    public:
        callback() {}
};

template< typename ARG_TYPE0>
class callback<void( ARG_TYPE0)>
{
    public:
        callback() {}
};

void f()
{
    callback<void(const int&)> op;
}
}

namespace PR9007 {
  struct bar {
    enum xxx {
      yyy = sizeof(struct foo*)
    };
    foo *xxx();
  };
}

namespace PR9026 {
  class InfallibleTArray {
  };
  class Variant;
  class CompVariant {
    operator const InfallibleTArray&() const;
  };
  class Variant {
    operator const CompVariant&() const;
  };
  void     Write(const Variant& __v);
  void     Write(const InfallibleTArray& __v);
  Variant x;
  void Write2() {
    Write(x);
  }
}

namespace PR10270 {
  template<typename T> class C;
  template<typename T> void f() {
    if (C<T> == 1) // expected-error{{expected unqualified-id}} \
                   // expected-error{{invalid '==' at end of declaration}}
      return;
  }
}

namespace rdar11806334 {

class cc_YCbCr;

class cc_rgb
{
 public:
  cc_rgb( uint p ); // expected-error {{unknown type name}}
  cc_rgb( cc_YCbCr v_in );
};

class cc_hsl
{
 public:
  cc_rgb rgb();
  cc_YCbCr YCbCr();
};

class cc_YCbCr
{
 public:
  cc_YCbCr( const cc_rgb v_in );
};

cc_YCbCr cc_hsl::YCbCr()
{
 cc_YCbCr v_out = cc_YCbCr( rgb());
 return v_out;
}

}

namespace test1 {
  int getString(const int*);
  template<int a> class ELFObjectFile  {
    const int* sh;
    ELFObjectFile() {
      switch (*sh) {
      }
      int SectionName(getString(sh));
    }
  };
}

namespace test2 {
  struct fltSemantics ;
  const fltSemantics &foobar();
  void VisitCastExpr(int x) {
    switch (x) {
    case 42:
      const fltSemantics &Sem = foobar();
    }
  }
}
<|endoftext|>


<commit_before>// Copyright 2015 Alexandr Mansurov

#include <memory>
#include "../src/db/TableInterfaces.h"
#include "../src/db/XMLConnector.h"
#include "gtest/gtest.h"

TEST(XmlConnector, Create) {
  //const std::shared_ptr<DatabaseConnector> c = std::make_shared<XMLConnector>(XMLConnector("/tmp/ccdb.xml"));
  const DatabaseConnector * c = new XMLConnector("/tmp/ccdb.xml");
  delete c;
}

TEST(XmlConnectorTransaction, RequestMethodGet) {
  //const std::shared_ptr<DatabaseConnector> c = std::make_shared<XMLConnector>(XMLConnector("/tmp/ccdb.xml"));
  DatabaseConnector * c = new XMLConnector("/tmp/ccdb.xml");

  auto tr(c -> createTransaction());

  ASSERT_TRUE(0 == tr->getId());

  tr->setMethod(RequestMethod::GET);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::GET);

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<XMLConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(0));

  ASSERT_FALSE(tr2 == nullptr);
  ASSERT_TRUE(0 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::GET);
}

/*TEST(XmlConnectorTransaction, RequestMethodPost) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  ASSERT_TRUE(1 == tr->getId());

  tr->setMethod(RequestMethod::POST);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::POST);

  delete c;
  ASSERT_EQ(nullptr, c);

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(1));

  ASSERT_TRUE(1 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::POST);
}

TEST(XmlConnectorTransaction, RequestMethodConnect) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  ASSERT_TRUE(2 == tr->getId());

  tr->setMethod(RequestMethod::CONNECT);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::CONNECT);

  delete c;
  ASSERT_EQ(nullptr, c);

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(2));

  ASSERT_TRUE(2 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::CONNECT);
}

TEST(XmlConnectorTransaction, RequestMethodPut) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  ASSERT_TRUE(3 == tr->getId());

  tr->setMethod(RequestMethod::PUT);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::PUT);

  delete c;
  ASSERT_EQ(nullptr, c);

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(3));

  ASSERT_TRUE(3 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::PUT);
}

TEST(XmlConnectorTransaction, RequestMethodHead) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  ASSERT_TRUE(4 == tr->getId());

  tr->setMethod(RequestMethod::HEAD);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::HEAD);

  delete c;
  ASSERT_EQ(nullptr, c);

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(4));

  ASSERT_TRUE(4 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::HEAD);
}

TEST(XmlConnectorTransaction, Values) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  auto id(tr->getId());

  const HttpUri uri(HttpUriFactory::createUri("http://olga.majling.eu/Vyuka"))
  const ResponseStatus status(200);
  const std::string ctype("text/html");
  const std::string content("");
  const std::size_t verificationStatus(3);

  tr->setUri(uri);
  ASSERT_EQ(uri, tr->getUri());

  tr->setResponseStatus(status);
  ASSERT_EQ(status, tr->getResponseStatus());

  tr->setContentType(ctype);
  ASSERT_EQ(ctype, tr->getContentType());

  tr->setContent(content);
  ASSERT_EQ(content, tr->getContent());

  tr->setContent("");
  ASSERT_EQ("", tr->getContent());

  tr->setContent(&content);
  ASSERT_EQ(content, *(tr->getContent()));

  tr->setVerificationStatus(verificationStatus);
  ASSERT_EQ(verificationStatus, tr->getVerificationStatus());

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(id));
  ASSERT_EQ(id, tr2->getId());
  ASSERT_EQ(uri, tr2->getUri())
  ASSERT_EQ(ctype, tr2->getContentType());
  ASSERT_EQ(content, tr2->getContent());
  ASSERT_EQ(content, *(tr->getContent()));
  ASSERT_EQ(verificationStatus, tr2->getVerificationStatus());
}

//TODO 2 DB independent

TEST(XmlConnector, Finding) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  auto f(c -> createFinding());
  ASSERT_EQ(0, f->getFindingId());

  auto id tr->getId());
  f->setResponseId(id);
  ASSERT_EQ(id, f->getResponseId())

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto f2(c2->getFinding(0));

  ASSERT_EQ(0, f2->getFindingId());
  ASSERT_EQ(id, f2->getResponseId());
}

TEST(XmlConnector, Link) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr -> createTransaction());
  auto f -> createFinding());

  auto link(c->createLink(f));
  ASSERT_EQ(f->getFindingId(), link->getFindingId());

  auto uri(HttpUriFactory::createUri("http://www.cvut.cz"));
  link->setUri(uri);
  ASSERT_EQ(uri, link->getUri());

  ASSERT_FALSE(link->getProcessed());
  link->setProcessed(true);
  ASSERT_TRUE(link->getProcessed());

  auto id(tr->getId());
  link->setRequestId(id);
  ASSERT_EQ(id, link->getRequestId());

  auto fid(f->getFindingId());
  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto l(c2->getLink(fid));
  ASSERT_EQ(l->getFindingId(), fid);
  ASSERT_EQ(l->getUri(), uri);
  ASSERT_TRUE(l->getProcessed());
  ASSERT_EQ(id, l->getRequestId());
}

TEST(XmlConnector, Defect) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr(c -> createTransaction());
  auto f(c -> createFinding());

  auto id = d->getFindingId();

  auto d(c->createDefect(f));

  ASSERT_EQ(f->getFindingId(), id);

  const std::size_t type(8);
  const std::string evidence("...");
  const std::size_t location(7);

  d->setDefectType(type);
  d->setEvidence(evidence);
  d->setLocation(location);

  ASSERT_EQ(type, d->getDefectType());
  ASSERT_EQ(evidence, d->getEvidence());
  ASSERT_EQ(locatiom, d->getLocation());

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto d2(c2->getDefect(id));

  ASSERT_EQ(id, d2->getFindingId());
  ASSERT_EQ(type, d2->getDefectType());
  ASSERT_EQ(evidence, d2->getEvidence());
  ASSERT_EQ(locatiom, d2->getLocation());
}

TEST(XmlConnector, Annotation) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr(c -> createTransaction());
  auto f(c -> createFinding());
  auto an(c->createAnnotation(f));

  auto id(f->getFindingId);;
  ASSERT_EQ(id, an->getFindingId());

  const std::string comment("Comment");
  an->setComment(comment);
  ASSERT_EQ(comment, an->getComment());

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto an2(c2->getAnnotation(id));
  ASSERT_EQ(id, an->getFindingId());
  ASSERT_EQ(comment, an->getComment());
}

TEST(XmlConnector, DefectType) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto d(c->createDefectType());

  ASSERT_EQ(0, d->getId());

  const std::string desc("...");
  d->setDescription(desc);

  ASSERT_EQ(desc, d->getDescription());

  delete c;
  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto d2(c2->getDefectType(0));
  ASSERT_EQ(0, d2->getId());
  ASSERT_EQ(desc, d2->getDescription());
}

TEST(XmlConnector, VerificationStatus) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto vs(c->createVerificationStatus());

  ASSERT_EQ(0, vs->getId());

  const std::string desc("...");
  vs->setDescription(desc);
  ASSERT_EQ(desc, vs->getDescription());

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto vs2(c2->getVerificationStatus(0));

  ASSERT_EQ(0, vs2->getId());
  ASSERT_EQ(desc, vs2->getDescription());
}*/
<commit_msg>XML Connector test minor mod<commit_after>// Copyright 2015 Alexandr Mansurov

#include <memory>
#include "../src/db/TableInterfaces.h"
#include "../src/db/XMLConnector.h"
#include "gtest/gtest.h"

TEST(XMLConnector, Create) {
  //const std::shared_ptr<DatabaseConnector> c = std::make_shared<XMLConnector>(XMLConnector("/tmp/ccdb.xml"));
  const DatabaseConnector * c = new XMLConnector("/tmp/ccdb.xml");
  delete c;
}

TEST(XMLConnectorTransaction, RequestMethodGet) {
  //const std::shared_ptr<DatabaseConnector> c = std::make_shared<XMLConnector>(XMLConnector("/tmp/ccdb.xml"));
  DatabaseConnector * c = new XMLConnector("/tmp/ccdb.xml");

  auto tr(c -> createTransaction());

  ASSERT_TRUE(0 == tr->getId());

  tr->setMethod(RequestMethod::GET);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::GET);

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<XMLConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(0));

  ASSERT_FALSE(tr2 == nullptr);
  ASSERT_TRUE(0 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::GET);
}

/*TEST(XmlConnectorTransaction, RequestMethodPost) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  ASSERT_TRUE(1 == tr->getId());

  tr->setMethod(RequestMethod::POST);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::POST);

  delete c;
  ASSERT_EQ(nullptr, c);

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(1));

  ASSERT_TRUE(1 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::POST);
}

TEST(XmlConnectorTransaction, RequestMethodConnect) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  ASSERT_TRUE(2 == tr->getId());

  tr->setMethod(RequestMethod::CONNECT);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::CONNECT);

  delete c;
  ASSERT_EQ(nullptr, c);

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(2));

  ASSERT_TRUE(2 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::CONNECT);
}

TEST(XmlConnectorTransaction, RequestMethodPut) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  ASSERT_TRUE(3 == tr->getId());

  tr->setMethod(RequestMethod::PUT);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::PUT);

  delete c;
  ASSERT_EQ(nullptr, c);

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(3));

  ASSERT_TRUE(3 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::PUT);
}

TEST(XmlConnectorTransaction, RequestMethodHead) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  ASSERT_TRUE(4 == tr->getId());

  tr->setMethod(RequestMethod::HEAD);
  ASSERT_TRUE(tr->getMethod() == RequestMethod::HEAD);

  delete c;
  ASSERT_EQ(nullptr, c);

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(4));

  ASSERT_TRUE(4 == tr2->getId());
  ASSERT_TRUE(tr2->getMethod() == RequestMethod::HEAD);
}

TEST(XmlConnectorTransaction, Values) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  auto id(tr->getId());

  const HttpUri uri(HttpUriFactory::createUri("http://olga.majling.eu/Vyuka"))
  const ResponseStatus status(200);
  const std::string ctype("text/html");
  const std::string content("");
  const std::size_t verificationStatus(3);

  tr->setUri(uri);
  ASSERT_EQ(uri, tr->getUri());

  tr->setResponseStatus(status);
  ASSERT_EQ(status, tr->getResponseStatus());

  tr->setContentType(ctype);
  ASSERT_EQ(ctype, tr->getContentType());

  tr->setContent(content);
  ASSERT_EQ(content, tr->getContent());

  tr->setContent("");
  ASSERT_EQ("", tr->getContent());

  tr->setContent(&content);
  ASSERT_EQ(content, *(tr->getContent()));

  tr->setVerificationStatus(verificationStatus);
  ASSERT_EQ(verificationStatus, tr->getVerificationStatus());

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr2(c2->getTransaction(id));
  ASSERT_EQ(id, tr2->getId());
  ASSERT_EQ(uri, tr2->getUri())
  ASSERT_EQ(ctype, tr2->getContentType());
  ASSERT_EQ(content, tr2->getContent());
  ASSERT_EQ(content, *(tr->getContent()));
  ASSERT_EQ(verificationStatus, tr2->getVerificationStatus());
}

//TODO 2 DB independent

TEST(XmlConnector, Finding) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));

  auto tr(c -> createTransaction());

  auto f(c -> createFinding());
  ASSERT_EQ(0, f->getFindingId());

  auto id tr->getId());
  f->setResponseId(id);
  ASSERT_EQ(id, f->getResponseId())

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto f2(c2->getFinding(0));

  ASSERT_EQ(0, f2->getFindingId());
  ASSERT_EQ(id, f2->getResponseId());
}

TEST(XmlConnector, Link) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr -> createTransaction());
  auto f -> createFinding());

  auto link(c->createLink(f));
  ASSERT_EQ(f->getFindingId(), link->getFindingId());

  auto uri(HttpUriFactory::createUri("http://www.cvut.cz"));
  link->setUri(uri);
  ASSERT_EQ(uri, link->getUri());

  ASSERT_FALSE(link->getProcessed());
  link->setProcessed(true);
  ASSERT_TRUE(link->getProcessed());

  auto id(tr->getId());
  link->setRequestId(id);
  ASSERT_EQ(id, link->getRequestId());

  auto fid(f->getFindingId());
  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto l(c2->getLink(fid));
  ASSERT_EQ(l->getFindingId(), fid);
  ASSERT_EQ(l->getUri(), uri);
  ASSERT_TRUE(l->getProcessed());
  ASSERT_EQ(id, l->getRequestId());
}

TEST(XmlConnector, Defect) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr(c -> createTransaction());
  auto f(c -> createFinding());

  auto id = d->getFindingId();

  auto d(c->createDefect(f));

  ASSERT_EQ(f->getFindingId(), id);

  const std::size_t type(8);
  const std::string evidence("...");
  const std::size_t location(7);

  d->setDefectType(type);
  d->setEvidence(evidence);
  d->setLocation(location);

  ASSERT_EQ(type, d->getDefectType());
  ASSERT_EQ(evidence, d->getEvidence());
  ASSERT_EQ(locatiom, d->getLocation());

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto d2(c2->getDefect(id));

  ASSERT_EQ(id, d2->getFindingId());
  ASSERT_EQ(type, d2->getDefectType());
  ASSERT_EQ(evidence, d2->getEvidence());
  ASSERT_EQ(locatiom, d2->getLocation());
}

TEST(XmlConnector, Annotation) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto tr(c -> createTransaction());
  auto f(c -> createFinding());
  auto an(c->createAnnotation(f));

  auto id(f->getFindingId);;
  ASSERT_EQ(id, an->getFindingId());

  const std::string comment("Comment");
  an->setComment(comment);
  ASSERT_EQ(comment, an->getComment());

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto an2(c2->getAnnotation(id));
  ASSERT_EQ(id, an->getFindingId());
  ASSERT_EQ(comment, an->getComment());
}

TEST(XmlConnector, DefectType) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto d(c->createDefectType());

  ASSERT_EQ(0, d->getId());

  const std::string desc("...");
  d->setDescription(desc);

  ASSERT_EQ(desc, d->getDescription());

  delete c;
  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto d2(c2->getDefectType(0));
  ASSERT_EQ(0, d2->getId());
  ASSERT_EQ(desc, d2->getDescription());
}

TEST(XmlConnector, VerificationStatus) {
  const std::shared_ptr<DatabaseConnector> c = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto vs(c->createVerificationStatus());

  ASSERT_EQ(0, vs->getId());

  const std::string desc("...");
  vs->setDescription(desc);
  ASSERT_EQ(desc, vs->getDescription());

  delete c;

  const std::shared_ptr<DatabaseConnector> c2 = std::make_shared<DatabaseConnector>(XMLConnector("/tmp/ccdb.xml"));
  auto vs2(c2->getVerificationStatus(0));

  ASSERT_EQ(0, vs2->getId());
  ASSERT_EQ(desc, vs2->getDescription());
}*/
<|endoftext|>


<commit_before>#include "anki/scene/VisibilityTester.h"
#include "anki/scene/Scene.h"
#include "anki/scene/Camera.h"
#include "anki/scene/Renderable.h"
#include "anki/scene/Light.h"
#include "anki/renderer/Renderer.h"
#include "anki/core/ThreadPool.h"

namespace anki {

//==============================================================================
// Misc                                                                        =
//==============================================================================

//==============================================================================
struct DistanceSortFunctor
{
	Vec3 origin;

	bool operator()(SceneNode* a, SceneNode* b)
	{
		ANKI_ASSERT(a->getSpatial() != nullptr && b->getSpatial() != nullptr);

		F32 dist0 = origin.getDistanceSquared(
			a->getSpatial()->getSpatialOrigin());
		F32 dist1 = origin.getDistanceSquared(
			b->getSpatial()->getSpatialOrigin());

		return dist0 < dist1;
	}
};

//==============================================================================
struct MaterialSortFunctor
{
	// XXX
};

//==============================================================================
struct TestJob: ThreadJob
{
	U count;
	Scene::Types<SceneNode>::Container::iterator nodes;
	VisibilityInfo::Renderables* renderables;
	VisibilityInfo::Lights* lights;

	void operator()(U threadId, U threadsCount)
	{
		U64 start, end;
		choseStartEnd(threadId, threadsCount, count, start, end);

		for(auto it = nodes + start; it != nodes + end; it++)
		{
		}
	}
};

//==============================================================================
VisibilityTester::~VisibilityTester()
{}

//==============================================================================
void VisibilityTester::test(Frustumable& ref, Scene& scene, Renderer& r)
{
	VisibilityInfo& vinfo = ref.getVisibilityInfo();
	vinfo.renderables.clear();
	vinfo.lights.clear();

	for(auto it = scene.getAllNodesBegin(); it != scene.getAllNodesEnd(); it++)
	{
		SceneNode* node = *it;

		Frustumable* fr = node->getFrustumable();
		// Wont check the same
		if(&ref == fr)
		{
			continue;
		}

		Spatial* sp = node->getSpatial();
		if(!sp)
		{
			continue;
		}

		sp->disableFlag(Spatial::SF_VISIBLE);

		if(!ref.insideFrustum(*sp))
		{
			continue;
		}

		/*if(!r.doVisibilityTests(sp->getAabb()))
		{
			continue;
		}*/

		sp->enableFlag(Spatial::SF_VISIBLE);

		Renderable* r = node->getRenderable();
		if(r)
		{
			vinfo.renderables.push_back(node);
		}
		else
		{
			Light* l = node->getLight();
			if(l)
			{
				vinfo.lights.push_back(node);

				if(l->getShadowEnabled() && fr)
				{
					testLight(*l, scene);
				}
			}
		}
	}

	DistanceSortFunctor comp;
	comp.origin =
		ref.getSceneNode().getMovable()->getWorldTransform().getOrigin();
	std::sort(vinfo.lights.begin(), vinfo.lights.end(), comp);

	std::sort(vinfo.renderables.begin(), vinfo.renderables.end(), comp);
}

//==============================================================================
void VisibilityTester::testLight(Light& light, Scene& scene)
{
	Frustumable& ref = *light.getFrustumable();
	ANKI_ASSERT(&ref != nullptr);

	VisibilityInfo& vinfo = ref.getVisibilityInfo();
	vinfo.renderables.clear();
	vinfo.lights.clear();

	for(auto it = scene.getAllNodesBegin(); it != scene.getAllNodesEnd(); it++)
	{
		SceneNode* node = *it;

		Frustumable* fr = node->getFrustumable();
		// Wont check the same
		if(&ref == fr)
		{
			continue;
		}

		Spatial* sp = node->getSpatial();
		if(!sp)
		{
			continue;
		}

		if(!ref.insideFrustum(*sp))
		{
			continue;
		}

		sp->enableFlag(Spatial::SF_VISIBLE);

		Renderable* r = node->getRenderable();
		if(r)
		{
			vinfo.renderables.push_back(node);
		}
	}
}

} // end namespace anki
<commit_msg>parallel visibility<commit_after>#include "anki/scene/VisibilityTester.h"
#include "anki/scene/Scene.h"
#include "anki/scene/Camera.h"
#include "anki/scene/Renderable.h"
#include "anki/scene/Light.h"
#include "anki/renderer/Renderer.h"
#include "anki/core/ThreadPool.h"

namespace anki {

//==============================================================================
// Misc                                                                        =
//==============================================================================

//==============================================================================
struct DistanceSortFunctor
{
	Vec3 origin;

	bool operator()(SceneNode* a, SceneNode* b)
	{
		ANKI_ASSERT(a->getSpatial() != nullptr && b->getSpatial() != nullptr);

		F32 dist0 = origin.getDistanceSquared(
			a->getSpatial()->getSpatialOrigin());
		F32 dist1 = origin.getDistanceSquared(
			b->getSpatial()->getSpatialOrigin());

		return dist0 < dist1;
	}
};

//==============================================================================
struct MaterialSortFunctor
{
	// XXX
};

//==============================================================================
struct TestJob: ThreadJob
{
	U count;
	Scene::Types<SceneNode>::Container::iterator nodes;
	VisibilityInfo::Renderables* renderables;
	VisibilityInfo::Lights* lights;
	std::mutex* renderablesMtx;
	std::mutex* lightsMtx;
	Frustumable* frustumable;

	void operator()(U threadId, U threadsCount)
	{
		U64 start, end;
		choseStartEnd(threadId, threadsCount, count, start, end);
		const U TEMP_STORE_COUNT = 128;
		Array<SceneNode*, TEMP_STORE_COUNT> tmpRenderables;
		Array<SceneNode*, TEMP_STORE_COUNT> tmpLights;
		U renderablesIdx = 0;
		U lightsIdx = 0;

		for(auto it = nodes + start; it != nodes + end; it++)
		{
			SceneNode* node = *it;

			Frustumable* fr = node->getFrustumable();
			// Skip if it is the same
			if(frustumable == fr)
			{
				continue;
			}

			Spatial* sp = node->getSpatial();
			if(!sp)
			{
				continue;
			}

			sp->disableFlag(Spatial::SF_VISIBLE);

			if(!frustumable->insideFrustum(*sp))
			{
				continue;
			}

			/*if(!r.doVisibilityTests(sp->getAabb()))
			{
				continue;
			}*/

			sp->enableFlag(Spatial::SF_VISIBLE);

			Renderable* r = node->getRenderable();
			if(r)
			{
				tmpRenderables[renderablesIdx++] = node;
			}
			else
			{
				Light* l = node->getLight();
				if(l)
				{
					tmpLights[lightsIdx++] = node;

					/*if(l->getShadowEnabled() && fr)
					{
						testLight(*l, scene);
					}*/
				}
			}
		} // end for

		// Write to containers
		if(renderablesIdx > 0)
		{
			std::lock_guard<std::mutex> lock(*renderablesMtx);

			renderables->insert(renderables->begin(),
				&tmpRenderables[0],
				&tmpRenderables[renderablesIdx]);
		}

		if(lightsIdx > 0)
		{
			std::lock_guard<std::mutex> lock(*lightsMtx);

			lights->insert(lights->begin(),
				&tmpLights[0],
				&tmpLights[lightsIdx]);
		}
	}
};

//==============================================================================
VisibilityTester::~VisibilityTester()
{}

//==============================================================================
void VisibilityTester::test(Frustumable& ref, Scene& scene, Renderer& r)
{
	VisibilityInfo& vinfo = ref.getVisibilityInfo();
	vinfo.renderables.clear();
	vinfo.lights.clear();

	for(auto it = scene.getAllNodesBegin(); it != scene.getAllNodesEnd(); it++)
	{
		SceneNode* node = *it;

		Frustumable* fr = node->getFrustumable();
		// Wont check the same
		if(&ref == fr)
		{
			continue;
		}

		Spatial* sp = node->getSpatial();
		if(!sp)
		{
			continue;
		}

		sp->disableFlag(Spatial::SF_VISIBLE);

		if(!ref.insideFrustum(*sp))
		{
			continue;
		}

		/*if(!r.doVisibilityTests(sp->getAabb()))
		{
			continue;
		}*/

		sp->enableFlag(Spatial::SF_VISIBLE);

		Renderable* r = node->getRenderable();
		if(r)
		{
			vinfo.renderables.push_back(node);
		}
		else
		{
			Light* l = node->getLight();
			if(l)
			{
				vinfo.lights.push_back(node);

				if(l->getShadowEnabled() && fr)
				{
					testLight(*l, scene);
				}
			}
		}
	}

	DistanceSortFunctor comp;
	comp.origin =
		ref.getSceneNode().getMovable()->getWorldTransform().getOrigin();
	std::sort(vinfo.lights.begin(), vinfo.lights.end(), comp);

	std::sort(vinfo.renderables.begin(), vinfo.renderables.end(), comp);
}

//==============================================================================
void VisibilityTester::testLight(Light& light, Scene& scene)
{
	Frustumable& ref = *light.getFrustumable();
	ANKI_ASSERT(&ref != nullptr);

	VisibilityInfo& vinfo = ref.getVisibilityInfo();
	vinfo.renderables.clear();
	vinfo.lights.clear();

	for(auto it = scene.getAllNodesBegin(); it != scene.getAllNodesEnd(); it++)
	{
		SceneNode* node = *it;

		Frustumable* fr = node->getFrustumable();
		// Wont check the same
		if(&ref == fr)
		{
			continue;
		}

		Spatial* sp = node->getSpatial();
		if(!sp)
		{
			continue;
		}

		if(!ref.insideFrustum(*sp))
		{
			continue;
		}

		sp->enableFlag(Spatial::SF_VISIBLE);

		Renderable* r = node->getRenderable();
		if(r)
		{
			vinfo.renderables.push_back(node);
		}
	}
}

} // end namespace anki
<|endoftext|>


<commit_before>// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "main.h"

template<typename MatrixType> void replicate(const MatrixType& m)
{
  /* this test covers the following files:
     Replicate.cpp
  */
  typedef typename MatrixType::Index Index;
  typedef typename MatrixType::Scalar Scalar;
  typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
  typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX;
  typedef Matrix<Scalar, Dynamic, 1> VectorX;

  Index rows = m.rows();
  Index cols = m.cols();

  MatrixType m1 = MatrixType::Random(rows, cols),
             m2 = MatrixType::Random(rows, cols);

  VectorType v1 = VectorType::Random(rows);

  MatrixX x1, x2;
  VectorX vx1;

  int  f1 = internal::random<int>(1,10),
       f2 = internal::random<int>(1,10);

  x1.resize(rows*f1,cols*f2);
  for(int j=0; j<f2; j++)
  for(int i=0; i<f1; i++)
    x1.block(i*rows,j*cols,rows,cols) = m1;
  VERIFY_IS_APPROX(x1, m1.replicate(f1,f2));

  x2.resize(2*rows,3*cols);
  x2 << m2, m2, m2,
        m2, m2, m2;
  VERIFY_IS_APPROX(x2, (m2.template replicate<2,3>()));

  x2.resize(rows,f1);
  for (int j=0; j<f1; ++j)
    x2.col(j) = v1;
  VERIFY_IS_APPROX(x2, v1.rowwise().replicate(f1));

  vx1.resize(rows*f2);
  for (int j=0; j<f2; ++j)
    vx1.segment(j*rows,rows) = v1;
  VERIFY_IS_APPROX(vx1, v1.colwise().replicate(f2));
}

void test_array_replicate()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST_1( replicate(Matrix<float, 1, 1>()) );
    CALL_SUBTEST_2( replicate(Vector2f()) );
    CALL_SUBTEST_3( replicate(Vector3d()) );
    CALL_SUBTEST_4( replicate(Vector4f()) );
    CALL_SUBTEST_5( replicate(VectorXf(16)) );
    CALL_SUBTEST_6( replicate(VectorXcd(10)) );
  }
}
<commit_msg>Add unit test for m.replicate(...)(index).<commit_after>// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "main.h"

template<typename MatrixType> void replicate(const MatrixType& m)
{
  /* this test covers the following files:
     Replicate.cpp
  */
  typedef typename MatrixType::Index Index;
  typedef typename MatrixType::Scalar Scalar;
  typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
  typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX;
  typedef Matrix<Scalar, Dynamic, 1> VectorX;

  Index rows = m.rows();
  Index cols = m.cols();

  MatrixType m1 = MatrixType::Random(rows, cols),
             m2 = MatrixType::Random(rows, cols);

  VectorType v1 = VectorType::Random(rows);

  MatrixX x1, x2;
  VectorX vx1;

  int  f1 = internal::random<int>(1,10),
       f2 = internal::random<int>(1,10);

  x1.resize(rows*f1,cols*f2);
  for(int j=0; j<f2; j++)
  for(int i=0; i<f1; i++)
    x1.block(i*rows,j*cols,rows,cols) = m1;
  VERIFY_IS_APPROX(x1, m1.replicate(f1,f2));

  x2.resize(2*rows,3*cols);
  x2 << m2, m2, m2,
        m2, m2, m2;
  VERIFY_IS_APPROX(x2, (m2.template replicate<2,3>()));

  x2.resize(rows,3*cols);
  x2 << m2, m2, m2;
  VERIFY_IS_APPROX(x2, (m2.template replicate<1,3>()));

  vx1.resize(3*rows,cols);
  vx1 << m2, m2, m2;
  VERIFY_IS_APPROX(vx1+vx1, vx1+(m2.template replicate<3,1>()));

  vx1=m2+(m2.colwise().replicate(1));

  if(m2.cols()==1)
    VERIFY_IS_APPROX(m2.coeff(0), (m2.template replicate<3,1>().coeff(m2.rows())));

  x2.resize(rows,f1);
  for (int j=0; j<f1; ++j)
    x2.col(j) = v1;
  VERIFY_IS_APPROX(x2, v1.rowwise().replicate(f1));

  vx1.resize(rows*f2);
  for (int j=0; j<f2; ++j)
    vx1.segment(j*rows,rows) = v1;
  VERIFY_IS_APPROX(vx1, v1.colwise().replicate(f2));
}

void test_array_replicate()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST_1( replicate(Matrix<float, 1, 1>()) );
    CALL_SUBTEST_2( replicate(Vector2f()) );
    CALL_SUBTEST_3( replicate(Vector3d()) );
    CALL_SUBTEST_4( replicate(Vector4f()) );
    CALL_SUBTEST_5( replicate(VectorXf(16)) );
    CALL_SUBTEST_6( replicate(VectorXcd(10)) );
  }
}
<|endoftext|>


<commit_before>#include <Arduino.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <ESP8266Wifi.h>
#include <SPI.h>
#include <NTPClient.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include <RCSwitch.h>

#include "PowerTimer.h"
#include "constants.h"
#include "config.h"

WiFiUDP ntpUDP;
NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_TIME_OFFSET, NTP_DEFAULT_SYNC);

RCSwitch rcswitch = RCSwitch();
ESP8266WebServer server(80);

time_t updateTimeFromNTP() {
  Serial.print("Refresh clock from ntp: ");
  Serial.print(ntpClient.getFormattedTime());

  Serial.print(", epoch time is: ");
  Serial.println(ntpClient.getEpochTime());

  return ntpClient.getEpochTime();
}

void pulse() {
  analogWrite(ILED, 255-(exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0);
}

socket_timer_t* get_socket_timer(AlarmID_t alarm_id) {
  for (int i = 0; i < sizeof(timers) / sizeof(socket_timer_t); i++) {
    if (timers[i].alarm_id == alarm_id) {
      return &timers[i];
    }
  }

  return NULL;
}

void socket_timer_callback() {
  AlarmID_t alarm_id = Alarm.getTriggeredAlarmId();

  socket_timer_t *object = get_socket_timer(alarm_id);
  if (object == NULL) {
    Serial.print("Unable to resolve alarm w/ id ");
    Serial.println(alarm_id);
  }

  Serial.print("Triggered alarm is ");
  Serial.println(alarm_id);

  socket_timer_execute(object);
}

void register_socket_timer(socket_timer_t *socket_timer) {
  AlarmID_t alarm_id = Alarm.alarmRepeat(socket_timer->hour, socket_timer->minute, socket_timer->second, socket_timer_callback);
  socket_timer->alarm_id = alarm_id;

  Serial.println("* Registered " + socket_timer_toString(socket_timer));
}

void setup() {
  Serial.begin(9600);
  Serial.println();

  pinMode(ILED, OUTPUT);
  analogWriteRange(255);
  digitalWrite(ILED, HIGH);

  rcswitch.enableTransmit(RCSWITCH_PIN);
  delay(250);

  Serial.print("Attempting to connect to SSID ");
  Serial.println(WLAN_SSID);
  WiFi.begin(WLAN_SSID, WLAN_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();

  Serial.print("Connected to SSID ");
  Serial.print(WLAN_SSID);
  Serial.print(" @ ");
  Serial.println(WiFi.localIP());

  ntpClient.begin();
  ntpClient.update();

  Serial.println("Registering NTP update service ...");
  setSyncProvider(updateTimeFromNTP);
  setSyncInterval(60);

  setupHttpService();

  Serial.println("Registering alarms ...");

  for (int i = 0; i < sizeof(timers) / sizeof(socket_timer_t); i++) {
    register_socket_timer(&timers[i]);
  }

  Serial.println("Boot up sequence finished.");
}

void setupHttpService() {
  Serial.println("Starting HTTP service ...");

  server.on("/", []() {
    String page = "Power service running
Control sockets:
";
    page += "<form method='get'>
";

    for (int i = 0; i < sizeof(sockets) / sizeof(socket_t); i++) {
      page += "
Socket " + sockets[i].name + " ON | OFF
";
    }

    page += "
";
    server.send(200, "text/html", page);
  });

  server.on("/socket", HTTP_GET, []() {
    String number = server.arg("n");
    String cmd = server.arg("s");

    int index = number.toInt();

    if (index < 0 || index > sizeof(sockets) / sizeof(socket_t)) {
      server.send(404, "text/plain", "Socket index not found.");
      return;
    }

    bool enable = (0 == cmd.compareTo("on"));
    Serial.println("Execute on HTTP, turn " + (enable ? String("ON") : String("OFF")) + " socket " + socket_toString(&sockets[index]));
    socket_execute_command(enable, &sockets[index]);
    server.send(200, "text/html", "<meta http-equiv='refresh' content='3, url=/'/>Ok, switched socket '" + sockets[index].name + "'\n");
  });

  server.begin();
  Serial.println("HTTP ready.");
}

void loop() {

  pulse();

  // Let NTP client sync
  ntpClient.update();

  // Alarms handler
  Alarm.delay(10);

  // Service HTTP clients
  server.handleClient();
}
<commit_msg>Make status LED blink while WiFi connect...<commit_after>#include <Arduino.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <ESP8266Wifi.h>
#include <SPI.h>
#include <NTPClient.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include <RCSwitch.h>

#include "PowerTimer.h"
#include "constants.h"
#include "config.h"

WiFiUDP ntpUDP;
NTPClient ntpClient(ntpUDP, NTP_SERVER, NTP_TIME_OFFSET, NTP_DEFAULT_SYNC);

RCSwitch rcswitch = RCSwitch();
ESP8266WebServer server(80);

time_t updateTimeFromNTP() {
  Serial.print("Refresh clock from ntp: ");
  Serial.print(ntpClient.getFormattedTime());

  Serial.print(", epoch time is: ");
  Serial.println(ntpClient.getEpochTime());

  return ntpClient.getEpochTime();
}

void pulse() {
  analogWrite(ILED, 255-(exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0);
}

socket_timer_t* get_socket_timer(AlarmID_t alarm_id) {
  for (int i = 0; i < sizeof(timers) / sizeof(socket_timer_t); i++) {
    if (timers[i].alarm_id == alarm_id) {
      return &timers[i];
    }
  }

  return NULL;
}

void socket_timer_callback() {
  AlarmID_t alarm_id = Alarm.getTriggeredAlarmId();

  socket_timer_t *object = get_socket_timer(alarm_id);
  if (object == NULL) {
    Serial.print("Unable to resolve alarm w/ id ");
    Serial.println(alarm_id);
  }

  Serial.print("Triggered alarm is ");
  Serial.println(alarm_id);

  socket_timer_execute(object);
}

void register_socket_timer(socket_timer_t *socket_timer) {
  AlarmID_t alarm_id = Alarm.alarmRepeat(socket_timer->hour, socket_timer->minute, socket_timer->second, socket_timer_callback);
  socket_timer->alarm_id = alarm_id;

  Serial.println("* Registered " + socket_timer_toString(socket_timer));
}

void setup() {
  Serial.begin(9600);
  Serial.println();

  pinMode(ILED, OUTPUT);
  analogWriteRange(255);
  digitalWrite(ILED, HIGH);

  rcswitch.enableTransmit(RCSWITCH_PIN);
  delay(250);

  Serial.print("Attempting to connect to SSID ");
  Serial.println(WLAN_SSID);
  WiFi.begin(WLAN_SSID, WLAN_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    digitalWrite(ILED, LOW);
    delay(300);
    digitalWrite(ILED, HIGH);
    delay(200);
  }
  Serial.println();

  Serial.print("Connected to SSID ");
  Serial.print(WLAN_SSID);
  Serial.print(" @ ");
  Serial.println(WiFi.localIP());

  ntpClient.begin();
  ntpClient.update();

  Serial.println("Registering NTP update service ...");
  setSyncProvider(updateTimeFromNTP);
  setSyncInterval(60);

  setupHttpService();

  Serial.println("Registering alarms ...");

  for (int i = 0; i < sizeof(timers) / sizeof(socket_timer_t); i++) {
    register_socket_timer(&timers[i]);
  }

  Serial.println("Boot up sequence finished.");
}

void setupHttpService() {
  Serial.println("Starting HTTP service ...");

  server.on("/", []() {
    String page = "Power service running
Control sockets:
";
    page += "<form method='get'>
";

    for (int i = 0; i < sizeof(sockets) / sizeof(socket_t); i++) {
      page += "
Socket " + sockets[i].name + " ON | OFF
";
    }

    page += "
";
    server.send(200, "text/html", page);
  });

  server.on("/socket", HTTP_GET, []() {
    String number = server.arg("n");
    String cmd = server.arg("s");

    int index = number.toInt();

    if (index < 0 || index > sizeof(sockets) / sizeof(socket_t)) {
      server.send(404, "text/plain", "Socket index not found.");
      return;
    }

    bool enable = (0 == cmd.compareTo("on"));
    Serial.println("Execute on HTTP, turn " + (enable ? String("ON") : String("OFF")) + " socket " + socket_toString(&sockets[index]));
    socket_execute_command(enable, &sockets[index]);
    server.send(200, "text/html", "<meta http-equiv='refresh' content='3, url=/'/>Ok, switched socket '" + sockets[index].name + "'\n");
  });

  server.begin();
  Serial.println("HTTP ready.");
}

void loop() {

  pulse();

  // Let NTP client sync
  ntpClient.update();

  // Alarms handler
  Alarm.delay(10);

  // Service HTTP clients
  server.handleClient();
}
<|endoftext|>