Commit 963b3555 authored by Daniel Seither's avatar Daniel Seither

Add test for multiple +o interfaces implemented by one class

parent 69402ad2
......@@ -10,3 +10,4 @@
@import "test.djinni"
@import "primtypes.djinni"
@import "constants.djinni"
@import "listeners.djinni"
first_listener = interface +o {
first();
}
second_listener = interface +o {
second();
}
listener_caller = interface +c {
static init(first_l: first_listener, second_l: second_listener): listener_caller;
callFirst();
callSecond();
}
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#pragma once
namespace testsuite {
class FirstListener {
public:
virtual ~FirstListener() {}
virtual void first() = 0;
};
} // namespace testsuite
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#pragma once
#include <memory>
namespace testsuite {
class FirstListener;
class SecondListener;
class ListenerCaller {
public:
virtual ~ListenerCaller() {}
static std::shared_ptr<ListenerCaller> init(const std::shared_ptr<FirstListener> & first_l, const std::shared_ptr<SecondListener> & second_l);
virtual void callFirst() = 0;
virtual void callSecond() = 0;
};
} // namespace testsuite
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#pragma once
namespace testsuite {
class SecondListener {
public:
virtual ~SecondListener() {}
virtual void second() = 0;
};
} // namespace testsuite
......@@ -12,6 +12,7 @@ djinni/user_token.djinni
djinni/test.djinni
djinni/primtypes.djinni
djinni/constants.djinni
djinni/listeners.djinni
djinni/date.djinni
djinni/date.yaml
djinni/duration.djinni
......
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
package com.dropbox.djinni.test;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
public abstract class FirstListener {
public abstract void first();
}
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
package com.dropbox.djinni.test;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
public abstract class ListenerCaller {
public abstract void callFirst();
public abstract void callSecond();
@CheckForNull
public static native ListenerCaller init(@CheckForNull FirstListener firstL, @CheckForNull SecondListener secondL);
private static final class CppProxy extends ListenerCaller
{
private final long nativeRef;
private final AtomicBoolean destroyed = new AtomicBoolean(false);
private CppProxy(long nativeRef)
{
if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
this.nativeRef = nativeRef;
}
private native void nativeDestroy(long nativeRef);
public void destroy()
{
boolean destroyed = this.destroyed.getAndSet(true);
if (!destroyed) nativeDestroy(this.nativeRef);
}
protected void finalize() throws java.lang.Throwable
{
destroy();
super.finalize();
}
@Override
public void callFirst()
{
assert !this.destroyed.get() : "trying to use a destroyed object";
native_callFirst(this.nativeRef);
}
private native void native_callFirst(long _nativeRef);
@Override
public void callSecond()
{
assert !this.destroyed.get() : "trying to use a destroyed object";
native_callSecond(this.nativeRef);
}
private native void native_callSecond(long _nativeRef);
}
}
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
package com.dropbox.djinni.test;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
public abstract class SecondListener {
public abstract void second();
}
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#include "NativeFirstListener.hpp" // my header
namespace djinni_generated {
NativeFirstListener::NativeFirstListener() : ::djinni::JniInterface<::testsuite::FirstListener, NativeFirstListener>() {}
NativeFirstListener::~NativeFirstListener() = default;
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#pragma once
#include "djinni_support.hpp"
#include "first_listener.hpp"
namespace djinni_generated {
class NativeFirstListener final : ::djinni::JniInterface<::testsuite::FirstListener, NativeFirstListener> {
public:
using CppType = std::shared_ptr<::testsuite::FirstListener>;
using CppOptType = std::shared_ptr<::testsuite::FirstListener>;
using JniType = jobject;
using Boxed = NativeFirstListener;
~NativeFirstListener();
static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass<NativeFirstListener>::get()._fromJava(jniEnv, j); }
static ::djinni::LocalRef<JniType> fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass<NativeFirstListener>::get()._toJava(jniEnv, c)}; }
static ::djinni::LocalRef<JniType> fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); }
private:
NativeFirstListener();
friend ::djinni::JniClass<NativeFirstListener>;
friend ::djinni::JniInterface<::testsuite::FirstListener, NativeFirstListener>;
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#include "NativeListenerCaller.hpp" // my header
#include "NativeFirstListener.hpp"
#include "NativeListenerCaller.hpp"
#include "NativeSecondListener.hpp"
namespace djinni_generated {
NativeListenerCaller::NativeListenerCaller() : ::djinni::JniInterface<::testsuite::ListenerCaller, NativeListenerCaller>("com/dropbox/djinni/test/ListenerCaller$CppProxy") {}
NativeListenerCaller::~NativeListenerCaller() = default;
CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_ListenerCaller_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef)
{
try {
DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef);
delete reinterpret_cast<djinni::CppProxyHandle<::testsuite::ListenerCaller>*>(nativeRef);
} JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, )
}
CJNIEXPORT jobject JNICALL Java_com_dropbox_djinni_test_ListenerCaller_init(JNIEnv* jniEnv, jobject /*this*/, jobject j_firstL, jobject j_secondL)
{
try {
DJINNI_FUNCTION_PROLOGUE0(jniEnv);
auto r = ::testsuite::ListenerCaller::init(::djinni_generated::NativeFirstListener::toCpp(jniEnv, j_firstL),
::djinni_generated::NativeSecondListener::toCpp(jniEnv, j_secondL));
return ::djinni::release(::djinni_generated::NativeListenerCaller::fromCpp(jniEnv, r));
} JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, 0 /* value doesn't matter */)
}
CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_ListenerCaller_00024CppProxy_native_1callFirst(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef)
{
try {
DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef);
const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::ListenerCaller>(nativeRef);
ref->callFirst();
} JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, )
}
CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_ListenerCaller_00024CppProxy_native_1callSecond(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef)
{
try {
DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef);
const auto& ref = ::djinni::objectFromHandleAddress<::testsuite::ListenerCaller>(nativeRef);
ref->callSecond();
} JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, )
}
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#pragma once
#include "djinni_support.hpp"
#include "listener_caller.hpp"
namespace djinni_generated {
class NativeListenerCaller final : ::djinni::JniInterface<::testsuite::ListenerCaller, NativeListenerCaller> {
public:
using CppType = std::shared_ptr<::testsuite::ListenerCaller>;
using CppOptType = std::shared_ptr<::testsuite::ListenerCaller>;
using JniType = jobject;
using Boxed = NativeListenerCaller;
~NativeListenerCaller();
static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass<NativeListenerCaller>::get()._fromJava(jniEnv, j); }
static ::djinni::LocalRef<JniType> fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass<NativeListenerCaller>::get()._toJava(jniEnv, c)}; }
static ::djinni::LocalRef<JniType> fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); }
private:
NativeListenerCaller();
friend ::djinni::JniClass<NativeListenerCaller>;
friend ::djinni::JniInterface<::testsuite::ListenerCaller, NativeListenerCaller>;
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#include "NativeSecondListener.hpp" // my header
namespace djinni_generated {
NativeSecondListener::NativeSecondListener() : ::djinni::JniInterface<::testsuite::SecondListener, NativeSecondListener>() {}
NativeSecondListener::~NativeSecondListener() = default;
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#pragma once
#include "djinni_support.hpp"
#include "second_listener.hpp"
namespace djinni_generated {
class NativeSecondListener final : ::djinni::JniInterface<::testsuite::SecondListener, NativeSecondListener> {
public:
using CppType = std::shared_ptr<::testsuite::SecondListener>;
using CppOptType = std::shared_ptr<::testsuite::SecondListener>;
using JniType = jobject;
using Boxed = NativeSecondListener;
~NativeSecondListener();
static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass<NativeSecondListener>::get()._fromJava(jniEnv, j); }
static ::djinni::LocalRef<JniType> fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass<NativeSecondListener>::get()._toJava(jniEnv, c)}; }
static ::djinni::LocalRef<JniType> fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); }
private:
NativeSecondListener();
friend ::djinni::JniClass<NativeSecondListener>;
friend ::djinni::JniInterface<::testsuite::SecondListener, NativeSecondListener>;
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#include "first_listener.hpp"
#include <memory>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@protocol DBFirstListener;
namespace djinni_generated {
class FirstListener
{
public:
using CppType = std::shared_ptr<::testsuite::FirstListener>;
using CppOptType = std::shared_ptr<::testsuite::FirstListener>;
using ObjcType = id<DBFirstListener>;
using Boxed = FirstListener;
static CppType toCpp(ObjcType objc);
static ObjcType fromCppOpt(const CppOptType& cpp);
static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); }
private:
class ObjcProxy;
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#import "DBFirstListener+Private.h"
#import "DBFirstListener.h"
#import "DJIObjcWrapperCache+Private.h"
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
namespace djinni_generated {
class FirstListener::ObjcProxy final
: public ::testsuite::FirstListener
, public ::djinni::ObjcProxyCache::Handle<ObjcType>
{
public:
using Handle::Handle;
void first() override
{
@autoreleasepool {
[Handle::get() first];
}
}
};
} // namespace djinni_generated
namespace djinni_generated {
auto FirstListener::toCpp(ObjcType objc) -> CppType
{
if (!objc) {
return nullptr;
}
return ::djinni::get_objc_proxy<ObjcProxy>(objc);
}
auto FirstListener::fromCppOpt(const CppOptType& cpp) -> ObjcType
{
if (!cpp) {
return nil;
}
return dynamic_cast<ObjcProxy&>(*cpp).Handle::get();
}
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#import <Foundation/Foundation.h>
@protocol DBFirstListener
- (void)first;
@end
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#include "listener_caller.hpp"
#include <memory>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@class DBListenerCaller;
namespace djinni_generated {
class ListenerCaller
{
public:
using CppType = std::shared_ptr<::testsuite::ListenerCaller>;
using CppOptType = std::shared_ptr<::testsuite::ListenerCaller>;
using ObjcType = DBListenerCaller*;
using Boxed = ListenerCaller;
static CppType toCpp(ObjcType objc);
static ObjcType fromCppOpt(const CppOptType& cpp);
static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); }
private:
class ObjcProxy;
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#import "DBListenerCaller+Private.h"
#import "DBListenerCaller.h"
#import "DBFirstListener+Private.h"
#import "DBListenerCaller+Private.h"
#import "DBSecondListener+Private.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIError.h"
#include <exception>
#include <utility>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@interface DBListenerCaller ()
- (id)initWithCpp:(const std::shared_ptr<::testsuite::ListenerCaller>&)cppRef;
@end
@implementation DBListenerCaller {
::djinni::CppProxyCache::Handle<std::shared_ptr<::testsuite::ListenerCaller>> _cppRefHandle;
}
- (id)initWithCpp:(const std::shared_ptr<::testsuite::ListenerCaller>&)cppRef
{
if (self = [super init]) {
_cppRefHandle.assign(cppRef);
}
return self;
}
+ (nullable DBListenerCaller *)init:(nullable id<DBFirstListener>)firstL
secondL:(nullable id<DBSecondListener>)secondL {
try {
auto r = ::testsuite::ListenerCaller::init(::djinni_generated::FirstListener::toCpp(firstL),
::djinni_generated::SecondListener::toCpp(secondL));
return ::djinni_generated::ListenerCaller::fromCpp(r);
} DJINNI_TRANSLATE_EXCEPTIONS()
}
- (void)callFirst {
try {
_cppRefHandle.get()->callFirst();
} DJINNI_TRANSLATE_EXCEPTIONS()
}
- (void)callSecond {
try {
_cppRefHandle.get()->callSecond();
} DJINNI_TRANSLATE_EXCEPTIONS()
}
namespace djinni_generated {
auto ListenerCaller::toCpp(ObjcType objc) -> CppType
{
if (!objc) {
return nullptr;
}
return objc->_cppRefHandle.get();
}
auto ListenerCaller::fromCppOpt(const CppOptType& cpp) -> ObjcType
{
if (!cpp) {
return nil;
}
return ::djinni::get_cpp_proxy<DBListenerCaller>(cpp);
}
} // namespace djinni_generated
@end
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#import <Foundation/Foundation.h>
@class DBListenerCaller;
@protocol DBFirstListener;
@protocol DBSecondListener;
@interface DBListenerCaller : NSObject
+ (nullable DBListenerCaller *)init:(nullable id<DBFirstListener>)firstL
secondL:(nullable id<DBSecondListener>)secondL;
- (void)callFirst;
- (void)callSecond;
@end
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#include "second_listener.hpp"
#include <memory>
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
@protocol DBSecondListener;
namespace djinni_generated {
class SecondListener
{
public:
using CppType = std::shared_ptr<::testsuite::SecondListener>;
using CppOptType = std::shared_ptr<::testsuite::SecondListener>;
using ObjcType = id<DBSecondListener>;
using Boxed = SecondListener;
static CppType toCpp(ObjcType objc);
static ObjcType fromCppOpt(const CppOptType& cpp);
static ObjcType fromCpp(const CppType& cpp) { return fromCppOpt(cpp); }
private:
class ObjcProxy;
};
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#import "DBSecondListener+Private.h"
#import "DBSecondListener.h"
#import "DJIObjcWrapperCache+Private.h"
static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
namespace djinni_generated {
class SecondListener::ObjcProxy final
: public ::testsuite::SecondListener
, public ::djinni::ObjcProxyCache::Handle<ObjcType>
{
public:
using Handle::Handle;
void second() override
{
@autoreleasepool {
[Handle::get() second];
}
}
};
} // namespace djinni_generated
namespace djinni_generated {
auto SecondListener::toCpp(ObjcType objc) -> CppType
{
if (!objc) {
return nullptr;
}
return ::djinni::get_objc_proxy<ObjcProxy>(objc);
}
auto SecondListener::fromCppOpt(const CppOptType& cpp) -> ObjcType
{
if (!cpp) {
return nil;
}
return dynamic_cast<ObjcProxy&>(*cpp).Handle::get();
}
} // namespace djinni_generated
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from listeners.djinni
#import <Foundation/Foundation.h>
@protocol DBSecondListener
- (void)second;
@end
......@@ -4,6 +4,9 @@ djinni-output-temp/cpp/record_with_duration_and_derivings.cpp
djinni-output-temp/cpp/date_record.hpp
djinni-output-temp/cpp/date_record.cpp
djinni-output-temp/cpp/map_date_record.hpp
djinni-output-temp/cpp/first_listener.hpp
djinni-output-temp/cpp/second_listener.hpp
djinni-output-temp/cpp/listener_caller.hpp
djinni-output-temp/cpp/constant_record.hpp
djinni-output-temp/cpp/constants.hpp
djinni-output-temp/cpp/constants.cpp
......@@ -33,6 +36,9 @@ djinni-output-temp/java/TestDuration.java
djinni-output-temp/java/RecordWithDurationAndDerivings.java
djinni-output-temp/java/DateRecord.java
djinni-output-temp/java/MapDateRecord.java
djinni-output-temp/java/FirstListener.java
djinni-output-temp/java/SecondListener.java
djinni-output-temp/java/ListenerCaller.java
djinni-output-temp/java/ConstantRecord.java
djinni-output-temp/java/Constants.java
djinni-output-temp/java/ConstantsInterface.java
......@@ -61,6 +67,12 @@ djinni-output-temp/jni/NativeDateRecord.hpp
djinni-output-temp/jni/NativeDateRecord.cpp
djinni-output-temp/jni/NativeMapDateRecord.hpp
djinni-output-temp/jni/NativeMapDateRecord.cpp
djinni-output-temp/jni/NativeFirstListener.hpp
djinni-output-temp/jni/NativeFirstListener.cpp
djinni-output-temp/jni/NativeSecondListener.hpp
djinni-output-temp/jni/NativeSecondListener.cpp
djinni-output-temp/jni/NativeListenerCaller.hpp
djinni-output-temp/jni/NativeListenerCaller.cpp
djinni-output-temp/jni/NativeConstantRecord.hpp
djinni-output-temp/jni/NativeConstantRecord.cpp
djinni-output-temp/jni/NativeConstants.hpp
......@@ -107,6 +119,9 @@ djinni-output-temp/objc/DBDateRecord.h
djinni-output-temp/objc/DBDateRecord.mm
djinni-output-temp/objc/DBMapDateRecord.h
djinni-output-temp/objc/DBMapDateRecord.mm
djinni-output-temp/objc/DBFirstListener.h
djinni-output-temp/objc/DBSecondListener.h
djinni-output-temp/objc/DBListenerCaller.h
djinni-output-temp/objc/DBConstantRecord.h
djinni-output-temp/objc/DBConstantRecord.mm
djinni-output-temp/objc/DBConstants.h
......@@ -149,6 +164,12 @@ djinni-output-temp/objc/DBDateRecord+Private.h
djinni-output-temp/objc/DBDateRecord+Private.mm
djinni-output-temp/objc/DBMapDateRecord+Private.h
djinni-output-temp/objc/DBMapDateRecord+Private.mm
djinni-output-temp/objc/DBFirstListener+Private.h
djinni-output-temp/objc/DBFirstListener+Private.mm
djinni-output-temp/objc/DBSecondListener+Private.h
djinni-output-temp/objc/DBSecondListener+Private.mm
djinni-output-temp/objc/DBListenerCaller+Private.h
djinni-output-temp/objc/DBListenerCaller+Private.mm
djinni-output-temp/objc/DBConstantRecord+Private.h
djinni-output-temp/objc/DBConstantRecord+Private.mm
djinni-output-temp/objc/DBConstants+Private.h
......
#include "listener_caller.hpp"
#include "first_listener.hpp"
#include "second_listener.hpp"
namespace testsuite {
class ListenerCallerImpl : public ListenerCaller {
public:
ListenerCallerImpl(const std::shared_ptr<FirstListener> &firstListener, const std::shared_ptr<SecondListener> &secondListener)
: firstListener(firstListener), secondListener(secondListener)
{}
void callFirst() override {
firstListener->first();
}
void callSecond() override {
secondListener->second();
}
private:
std::shared_ptr<FirstListener> firstListener;
std::shared_ptr<SecondListener> secondListener;
};
std::shared_ptr<ListenerCaller> ListenerCaller::init(
const std::shared_ptr<FirstListener> &firstListener,
const std::shared_ptr<SecondListener> &secondListener) {
return std::make_shared<ListenerCallerImpl>(firstListener, secondListener);
}
} // namespace testsuite
#import <XCTest/XCTest.h>
#include "DBFirstListener.h"
#include "DBSecondListener.h"
#include "DBListenerCaller.h"
@interface Listener : NSObject <DBFirstListener, DBSecondListener>
@property bool firstCalled;
@property bool secondCalled;
@end
@implementation Listener
- (id) init {
self = [super init];
if (self != nil) {
self.firstCalled = FALSE;
self.secondCalled = FALSE;
}
return self;
}
- (void)first {
self.firstCalled = TRUE;
}
- (void)second {
self.secondCalled = TRUE;
}
@end
@interface DBListenerCallerTest : XCTestCase
@end
@implementation DBListenerCallerTest {
Listener *listener;
DBListenerCaller *caller;
}
- (void)setUp {
[super setUp];
listener = [Listener new];
caller = [DBListenerCaller init:listener secondL:listener];
}
- (void)testCallFirst {
[caller callFirst];
XCTAssert(listener.firstCalled);
}
- (void)testCallSecond {
[caller callSecond];
XCTAssert(listener.secondCalled);
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment