capnproto

FORK: Cap'n Proto serialization/RPC system - core tools and C++ library
git clone https://git.neptards.moe/neptards/capnproto.git
Log | Files | Refs | README | LICENSE

common-test.c++ (3259B)


      1 // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
      2 // Licensed under the MIT License:
      3 //
      4 // Permission is hereby granted, free of charge, to any person obtaining a copy
      5 // of this software and associated documentation files (the "Software"), to deal
      6 // in the Software without restriction, including without limitation the rights
      7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      8 // copies of the Software, and to permit persons to whom the Software is
      9 // furnished to do so, subject to the following conditions:
     10 //
     11 // The above copyright notice and this permission notice shall be included in
     12 // all copies or substantial portions of the Software.
     13 //
     14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     20 // THE SOFTWARE.
     21 
     22 #include "common.h"
     23 #include <kj/compat/gtest.h>
     24 #include <kj/string.h>
     25 #include <kj/debug.h>
     26 #include <capnp/test.capnp.h>
     27 
     28 #if HAVE_CONFIG_H
     29 #include "config.h"
     30 #endif
     31 
     32 namespace capnp {
     33 namespace {
     34 
     35 TEST(Common, Version) {
     36 #ifdef VERSION
     37   auto expectedVersion =
     38       kj::str(CAPNP_VERSION_MAJOR, '.', CAPNP_VERSION_MINOR, '.', CAPNP_VERSION_MICRO);
     39   auto devVersion =
     40       kj::str(CAPNP_VERSION_MAJOR, '.', CAPNP_VERSION_MINOR, "-dev");
     41   kj::StringPtr actualVersion = VERSION;
     42   KJ_ASSERT(actualVersion == expectedVersion ||
     43             actualVersion.startsWith(kj::str(expectedVersion, '-')) ||
     44             actualVersion.startsWith(kj::str(expectedVersion, '.')) ||
     45             (actualVersion == devVersion && CAPNP_VERSION_MICRO == 0),
     46             expectedVersion, actualVersion);
     47 #endif
     48 }
     49 
     50 struct ExampleStruct {
     51   struct _capnpPrivate {
     52     struct IsStruct;
     53   };
     54 };
     55 struct ExampleInterface {
     56   struct _capnpPrivate {
     57     struct IsInterface;
     58   };
     59 };
     60 
     61 static_assert(_::Kind_<ExampleStruct>::kind == Kind::STRUCT, "Kind SFINAE failed.");
     62 static_assert(_::Kind_<ExampleInterface>::kind == Kind::INTERFACE, "Kind SFINAE failed.");
     63 
     64 // Test FromAnay<>
     65 template <typename T, typename U>
     66 struct EqualTypes_ { static constexpr bool value = false; };
     67 
     68 template <typename T>
     69 struct EqualTypes_<T, T> { static constexpr bool value = true; };
     70 
     71 template <typename T, typename U>
     72 inline constexpr bool equalTypes() { return EqualTypes_<T, U>::value; }
     73 
     74 using capnproto_test::capnp::test::TestAllTypes;
     75 using capnproto_test::capnp::test::TestInterface;
     76 
     77 static_assert(equalTypes<FromAny<int>, int>(), "");
     78 static_assert(equalTypes<FromAny<TestAllTypes::Reader>, TestAllTypes>(), "");
     79 static_assert(equalTypes<FromAny<TestAllTypes::Builder>, TestAllTypes>(), "");
     80 #if !CAPNP_LITE
     81 static_assert(equalTypes<FromAny<TestAllTypes::Pipeline>, TestAllTypes>(), "");
     82 static_assert(equalTypes<FromAny<TestInterface::Client>, TestInterface>(), "");
     83 static_assert(equalTypes<FromAny<kj::Own<TestInterface::Server>>, TestInterface>(), "");
     84 #endif
     85 
     86 }  // namespace
     87 }  // namespace capnp