Commit 14ac0f69 authored by Andrew Twyman's avatar Andrew Twyman

Support eq and ord on dates

Fixes #223

Turns out eq and ord were never implemented for dates in Java or ObjC.
I implemented, and added that type to the record_with_derivings test.
parent 6a2164ef
......@@ -277,11 +277,10 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
skipFirst { w.wl(" &&") }
f.ty.resolved.base match {
case MBinary => w.w(s"java.util.Arrays.equals(${idJava.field(f.ident)}, other.${idJava.field(f.ident)})")
case MList | MSet | MMap => w.w(s"this.${idJava.field(f.ident)}.equals(other.${idJava.field(f.ident)})")
case MList | MSet | MMap | MString | MDate => w.w(s"this.${idJava.field(f.ident)}.equals(other.${idJava.field(f.ident)})")
case MOptional =>
w.w(s"((this.${idJava.field(f.ident)} == null && other.${idJava.field(f.ident)} == null) || ")
w.w(s"(this.${idJava.field(f.ident)} != null && this.${idJava.field(f.ident)}.equals(other.${idJava.field(f.ident)})))")
case MString => w.w(s"this.${idJava.field(f.ident)}.equals(other.${idJava.field(f.ident)})")
case t: MPrimitive => w.w(s"this.${idJava.field(f.ident)} == other.${idJava.field(f.ident)}")
case df: MDef => df.defType match {
case DRecord => w.w(s"this.${idJava.field(f.ident)}.equals(other.${idJava.field(f.ident)})")
......@@ -378,7 +377,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
w.wl("int tempResult;")
for (f <- r.fields) {
f.ty.resolved.base match {
case MString => w.wl(s"tempResult = this.${idJava.field(f.ident)}.compareTo(other.${idJava.field(f.ident)});")
case MString | MDate => w.wl(s"tempResult = this.${idJava.field(f.ident)}.compareTo(other.${idJava.field(f.ident)});")
case t: MPrimitive => primitiveCompare(f.ident)
case df: MDef => df.defType match {
case DRecord => w.wl(s"tempResult = this.${idJava.field(f.ident)}.compareTo(other.${idJava.field(f.ident)});")
......
......@@ -293,6 +293,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
w.w(s"(self.${idObjc.field(f.ident)} != nil && [self.${idObjc.field(f.ident)} isEqual:typedOther.${idObjc.field(f.ident)}]))")
}
case MString => w.w(s"[self.${idObjc.field(f.ident)} isEqualToString:typedOther.${idObjc.field(f.ident)}]")
case MDate => w.w(s"[self.${idObjc.field(f.ident)} isEqualToDate:typedOther.${idObjc.field(f.ident)}]")
case t: MPrimitive => w.w(s"self.${idObjc.field(f.ident)} == typedOther.${idObjc.field(f.ident)}")
case df: MDef => df.defType match {
case DRecord => w.w(s"[self.${idObjc.field(f.ident)} isEqual:typedOther.${idObjc.field(f.ident)}]")
......@@ -366,7 +367,7 @@ class ObjcGenerator(spec: Spec) extends Generator(spec) {
w.wl("NSComparisonResult tempResult;")
for (f <- r.fields) {
f.ty.resolved.base match {
case MString => w.wl(s"tempResult = [self.${idObjc.field(f.ident)} compare:other.${idObjc.field(f.ident)}];")
case MString | MDate => w.wl(s"tempResult = [self.${idObjc.field(f.ident)} compare:other.${idObjc.field(f.ident)}];")
case t: MPrimitive => generatePrimitiveOrder(f.ident, w)
case df: MDef => df.defType match {
case DRecord => w.wl(s"tempResult = [self.${idObjc.field(f.ident)} compare:other.${idObjc.field(f.ident)}];")
......
record_with_derivings = record {
key1: i32;
key2: string;
eight: i8;
sixteen: i16;
thirtytwo: i32;
sixtyfour: i64;
fthirtytwo: f32;
fsixtyfour: f64;
d: date;
s: string;
} deriving (eq, ord)
record_with_nested_derivings = record {
......
......@@ -7,8 +7,14 @@ namespace testsuite {
bool operator==(const RecordWithDerivings& lhs, const RecordWithDerivings& rhs) {
return lhs.key1 == rhs.key1 &&
lhs.key2 == rhs.key2;
return lhs.eight == rhs.eight &&
lhs.sixteen == rhs.sixteen &&
lhs.thirtytwo == rhs.thirtytwo &&
lhs.sixtyfour == rhs.sixtyfour &&
lhs.fthirtytwo == rhs.fthirtytwo &&
lhs.fsixtyfour == rhs.fsixtyfour &&
lhs.d == rhs.d &&
lhs.s == rhs.s;
}
bool operator!=(const RecordWithDerivings& lhs, const RecordWithDerivings& rhs) {
......@@ -16,16 +22,52 @@ bool operator!=(const RecordWithDerivings& lhs, const RecordWithDerivings& rhs)
}
bool operator<(const RecordWithDerivings& lhs, const RecordWithDerivings& rhs) {
if (lhs.key1 < rhs.key1) {
if (lhs.eight < rhs.eight) {
return true;
}
if (rhs.key1 < lhs.key1) {
if (rhs.eight < lhs.eight) {
return false;
}
if (lhs.key2 < rhs.key2) {
if (lhs.sixteen < rhs.sixteen) {
return true;
}
if (rhs.key2 < lhs.key2) {
if (rhs.sixteen < lhs.sixteen) {
return false;
}
if (lhs.thirtytwo < rhs.thirtytwo) {
return true;
}
if (rhs.thirtytwo < lhs.thirtytwo) {
return false;
}
if (lhs.sixtyfour < rhs.sixtyfour) {
return true;
}
if (rhs.sixtyfour < lhs.sixtyfour) {
return false;
}
if (lhs.fthirtytwo < rhs.fthirtytwo) {
return true;
}
if (rhs.fthirtytwo < lhs.fthirtytwo) {
return false;
}
if (lhs.fsixtyfour < rhs.fsixtyfour) {
return true;
}
if (rhs.fsixtyfour < lhs.fsixtyfour) {
return false;
}
if (lhs.d < rhs.d) {
return true;
}
if (rhs.d < lhs.d) {
return false;
}
if (lhs.s < rhs.s) {
return true;
}
if (rhs.s < lhs.s) {
return false;
}
return false;
......
......@@ -3,6 +3,7 @@
#pragma once
#include <chrono>
#include <cstdint>
#include <string>
#include <utility>
......@@ -10,8 +11,14 @@
namespace testsuite {
struct RecordWithDerivings final {
int32_t key1;
std::string key2;
int8_t eight;
int16_t sixteen;
int32_t thirtytwo;
int64_t sixtyfour;
float fthirtytwo;
double fsixtyfour;
std::chrono::system_clock::time_point d;
std::string s;
friend bool operator==(const RecordWithDerivings& lhs, const RecordWithDerivings& rhs);
friend bool operator!=(const RecordWithDerivings& lhs, const RecordWithDerivings& rhs);
......@@ -22,10 +29,22 @@ struct RecordWithDerivings final {
friend bool operator<=(const RecordWithDerivings& lhs, const RecordWithDerivings& rhs);
friend bool operator>=(const RecordWithDerivings& lhs, const RecordWithDerivings& rhs);
RecordWithDerivings(int32_t key1_,
std::string key2_)
: key1(std::move(key1_))
, key2(std::move(key2_))
RecordWithDerivings(int8_t eight_,
int16_t sixteen_,
int32_t thirtytwo_,
int64_t sixtyfour_,
float fthirtytwo_,
double fsixtyfour_,
std::chrono::system_clock::time_point d_,
std::string s_)
: eight(std::move(eight_))
, sixteen(std::move(sixteen_))
, thirtytwo(std::move(thirtytwo_))
, sixtyfour(std::move(sixtyfour_))
, fthirtytwo(std::move(fthirtytwo_))
, fsixtyfour(std::move(fsixtyfour_))
, d(std::move(d_))
, s(std::move(s_))
{}
};
......
......@@ -3,30 +3,80 @@
package com.dropbox.djinni.test;
import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
public class RecordWithDerivings implements Comparable<RecordWithDerivings> {
/*package*/ final int mKey1;
/*package*/ final byte mEight;
/*package*/ final String mKey2;
/*package*/ final short mSixteen;
/*package*/ final int mThirtytwo;
/*package*/ final long mSixtyfour;
/*package*/ final float mFthirtytwo;
/*package*/ final double mFsixtyfour;
/*package*/ final Date mD;
/*package*/ final String mS;
public RecordWithDerivings(
int key1,
@Nonnull String key2) {
this.mKey1 = key1;
this.mKey2 = key2;
byte eight,
short sixteen,
int thirtytwo,
long sixtyfour,
float fthirtytwo,
double fsixtyfour,
@Nonnull Date d,
@Nonnull String s) {
this.mEight = eight;
this.mSixteen = sixteen;
this.mThirtytwo = thirtytwo;
this.mSixtyfour = sixtyfour;
this.mFthirtytwo = fthirtytwo;
this.mFsixtyfour = fsixtyfour;
this.mD = d;
this.mS = s;
}
public byte getEight() {
return mEight;
}
public short getSixteen() {
return mSixteen;
}
public int getThirtytwo() {
return mThirtytwo;
}
public long getSixtyfour() {
return mSixtyfour;
}
public float getFthirtytwo() {
return mFthirtytwo;
}
public int getKey1() {
return mKey1;
public double getFsixtyfour() {
return mFsixtyfour;
}
@Nonnull
public String getKey2() {
return mKey2;
public Date getD() {
return mD;
}
@Nonnull
public String getS() {
return mS;
}
@Override
......@@ -35,24 +85,42 @@ public class RecordWithDerivings implements Comparable<RecordWithDerivings> {
return false;
}
RecordWithDerivings other = (RecordWithDerivings) obj;
return this.mKey1 == other.mKey1 &&
this.mKey2.equals(other.mKey2);
return this.mEight == other.mEight &&
this.mSixteen == other.mSixteen &&
this.mThirtytwo == other.mThirtytwo &&
this.mSixtyfour == other.mSixtyfour &&
this.mFthirtytwo == other.mFthirtytwo &&
this.mFsixtyfour == other.mFsixtyfour &&
this.mD.equals(other.mD) &&
this.mS.equals(other.mS);
}
@Override
public int hashCode() {
// Pick an arbitrary non-zero starting value
int hashCode = 17;
hashCode = hashCode * 31 + mKey1;
hashCode = hashCode * 31 + mKey2.hashCode();
hashCode = hashCode * 31 + mEight;
hashCode = hashCode * 31 + mSixteen;
hashCode = hashCode * 31 + mThirtytwo;
hashCode = hashCode * 31 + ((int) (mSixtyfour ^ (mSixtyfour >>> 32)));
hashCode = hashCode * 31 + Float.floatToIntBits(mFthirtytwo);
hashCode = hashCode * 31 + ((int) (Double.doubleToLongBits(mFsixtyfour) ^ (Double.doubleToLongBits(mFsixtyfour) >>> 32)));
hashCode = hashCode * 31 + mD.hashCode();
hashCode = hashCode * 31 + mS.hashCode();
return hashCode;
}
@Override
public String toString() {
return "RecordWithDerivings{" +
"mKey1=" + mKey1 +
"," + "mKey2=" + mKey2 +
"mEight=" + mEight +
"," + "mSixteen=" + mSixteen +
"," + "mThirtytwo=" + mThirtytwo +
"," + "mSixtyfour=" + mSixtyfour +
"," + "mFthirtytwo=" + mFthirtytwo +
"," + "mFsixtyfour=" + mFsixtyfour +
"," + "mD=" + mD +
"," + "mS=" + mS +
"}";
}
......@@ -60,9 +128,39 @@ public class RecordWithDerivings implements Comparable<RecordWithDerivings> {
@Override
public int compareTo(@Nonnull RecordWithDerivings other) {
int tempResult;
if (this.mKey1 < other.mKey1) {
if (this.mEight < other.mEight) {
tempResult = -1;
} else if (this.mEight > other.mEight) {
tempResult = 1;
} else {
tempResult = 0;
}
if (tempResult != 0) {
return tempResult;
}
if (this.mSixteen < other.mSixteen) {
tempResult = -1;
} else if (this.mSixteen > other.mSixteen) {
tempResult = 1;
} else {
tempResult = 0;
}
if (tempResult != 0) {
return tempResult;
}
if (this.mThirtytwo < other.mThirtytwo) {
tempResult = -1;
} else if (this.mThirtytwo > other.mThirtytwo) {
tempResult = 1;
} else {
tempResult = 0;
}
if (tempResult != 0) {
return tempResult;
}
if (this.mSixtyfour < other.mSixtyfour) {
tempResult = -1;
} else if (this.mKey1 > other.mKey1) {
} else if (this.mSixtyfour > other.mSixtyfour) {
tempResult = 1;
} else {
tempResult = 0;
......@@ -70,7 +168,31 @@ public class RecordWithDerivings implements Comparable<RecordWithDerivings> {
if (tempResult != 0) {
return tempResult;
}
tempResult = this.mKey2.compareTo(other.mKey2);
if (this.mFthirtytwo < other.mFthirtytwo) {
tempResult = -1;
} else if (this.mFthirtytwo > other.mFthirtytwo) {
tempResult = 1;
} else {
tempResult = 0;
}
if (tempResult != 0) {
return tempResult;
}
if (this.mFsixtyfour < other.mFsixtyfour) {
tempResult = -1;
} else if (this.mFsixtyfour > other.mFsixtyfour) {
tempResult = 1;
} else {
tempResult = 0;
}
if (tempResult != 0) {
return tempResult;
}
tempResult = this.mD.compareTo(other.mD);
if (tempResult != 0) {
return tempResult;
}
tempResult = this.mS.compareTo(other.mS);
if (tempResult != 0) {
return tempResult;
}
......
......@@ -13,18 +13,30 @@ NativeRecordWithDerivings::~NativeRecordWithDerivings() = default;
auto NativeRecordWithDerivings::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef<JniType> {
const auto& data = ::djinni::JniClass<NativeRecordWithDerivings>::get();
auto r = ::djinni::LocalRef<JniType>{jniEnv->NewObject(data.clazz.get(), data.jconstructor,
::djinni::get(::djinni::I32::fromCpp(jniEnv, c.key1)),
::djinni::get(::djinni::String::fromCpp(jniEnv, c.key2)))};
::djinni::get(::djinni::I8::fromCpp(jniEnv, c.eight)),
::djinni::get(::djinni::I16::fromCpp(jniEnv, c.sixteen)),
::djinni::get(::djinni::I32::fromCpp(jniEnv, c.thirtytwo)),
::djinni::get(::djinni::I64::fromCpp(jniEnv, c.sixtyfour)),
::djinni::get(::djinni::F32::fromCpp(jniEnv, c.fthirtytwo)),
::djinni::get(::djinni::F64::fromCpp(jniEnv, c.fsixtyfour)),
::djinni::get(::djinni::Date::fromCpp(jniEnv, c.d)),
::djinni::get(::djinni::String::fromCpp(jniEnv, c.s)))};
::djinni::jniExceptionCheck(jniEnv);
return r;
}
auto NativeRecordWithDerivings::toCpp(JNIEnv* jniEnv, JniType j) -> CppType {
::djinni::JniLocalScope jscope(jniEnv, 3);
::djinni::JniLocalScope jscope(jniEnv, 9);
assert(j != nullptr);
const auto& data = ::djinni::JniClass<NativeRecordWithDerivings>::get();
return {::djinni::I32::toCpp(jniEnv, jniEnv->GetIntField(j, data.field_mKey1)),
::djinni::String::toCpp(jniEnv, (jstring)jniEnv->GetObjectField(j, data.field_mKey2))};
return {::djinni::I8::toCpp(jniEnv, jniEnv->GetByteField(j, data.field_mEight)),
::djinni::I16::toCpp(jniEnv, jniEnv->GetShortField(j, data.field_mSixteen)),
::djinni::I32::toCpp(jniEnv, jniEnv->GetIntField(j, data.field_mThirtytwo)),
::djinni::I64::toCpp(jniEnv, jniEnv->GetLongField(j, data.field_mSixtyfour)),
::djinni::F32::toCpp(jniEnv, jniEnv->GetFloatField(j, data.field_mFthirtytwo)),
::djinni::F64::toCpp(jniEnv, jniEnv->GetDoubleField(j, data.field_mFsixtyfour)),
::djinni::Date::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mD)),
::djinni::String::toCpp(jniEnv, (jstring)jniEnv->GetObjectField(j, data.field_mS))};
}
} // namespace djinni_generated
......@@ -25,9 +25,15 @@ private:
friend ::djinni::JniClass<NativeRecordWithDerivings>;
const ::djinni::GlobalRef<jclass> clazz { ::djinni::jniFindClass("com/dropbox/djinni/test/RecordWithDerivings") };
const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "<init>", "(ILjava/lang/String;)V") };
const jfieldID field_mKey1 { ::djinni::jniGetFieldID(clazz.get(), "mKey1", "I") };
const jfieldID field_mKey2 { ::djinni::jniGetFieldID(clazz.get(), "mKey2", "Ljava/lang/String;") };
const jmethodID jconstructor { ::djinni::jniGetMethodID(clazz.get(), "<init>", "(BSIJFDLjava/util/Date;Ljava/lang/String;)V") };
const jfieldID field_mEight { ::djinni::jniGetFieldID(clazz.get(), "mEight", "B") };
const jfieldID field_mSixteen { ::djinni::jniGetFieldID(clazz.get(), "mSixteen", "S") };
const jfieldID field_mThirtytwo { ::djinni::jniGetFieldID(clazz.get(), "mThirtytwo", "I") };
const jfieldID field_mSixtyfour { ::djinni::jniGetFieldID(clazz.get(), "mSixtyfour", "J") };
const jfieldID field_mFthirtytwo { ::djinni::jniGetFieldID(clazz.get(), "mFthirtytwo", "F") };
const jfieldID field_mFsixtyfour { ::djinni::jniGetFieldID(clazz.get(), "mFsixtyfour", "D") };
const jfieldID field_mD { ::djinni::jniGetFieldID(clazz.get(), "mD", "Ljava/util/Date;") };
const jfieldID field_mS { ::djinni::jniGetFieldID(clazz.get(), "mS", "Ljava/lang/String;") };
};
} // namespace djinni_generated
......@@ -10,14 +10,26 @@ namespace djinni_generated {
auto RecordWithDerivings::toCpp(ObjcType obj) -> CppType
{
assert(obj);
return {::djinni::I32::toCpp(obj.key1),
::djinni::String::toCpp(obj.key2)};
return {::djinni::I8::toCpp(obj.eight),
::djinni::I16::toCpp(obj.sixteen),
::djinni::I32::toCpp(obj.thirtytwo),
::djinni::I64::toCpp(obj.sixtyfour),
::djinni::F32::toCpp(obj.fthirtytwo),
::djinni::F64::toCpp(obj.fsixtyfour),
::djinni::Date::toCpp(obj.d),
::djinni::String::toCpp(obj.s)};
}
auto RecordWithDerivings::fromCpp(const CppType& cpp) -> ObjcType
{
return [[DBRecordWithDerivings alloc] initWithKey1:(::djinni::I32::fromCpp(cpp.key1))
key2:(::djinni::String::fromCpp(cpp.key2))];
return [[DBRecordWithDerivings alloc] initWithEight:(::djinni::I8::fromCpp(cpp.eight))
sixteen:(::djinni::I16::fromCpp(cpp.sixteen))
thirtytwo:(::djinni::I32::fromCpp(cpp.thirtytwo))
sixtyfour:(::djinni::I64::fromCpp(cpp.sixtyfour))
fthirtytwo:(::djinni::F32::fromCpp(cpp.fthirtytwo))
fsixtyfour:(::djinni::F64::fromCpp(cpp.fsixtyfour))
d:(::djinni::Date::fromCpp(cpp.d))
s:(::djinni::String::fromCpp(cpp.s))];
}
} // namespace djinni_generated
......@@ -4,14 +4,38 @@
#import <Foundation/Foundation.h>
@interface DBRecordWithDerivings : NSObject
- (nonnull instancetype)initWithKey1:(int32_t)key1
key2:(nonnull NSString *)key2;
+ (nonnull instancetype)recordWithDerivingsWithKey1:(int32_t)key1
key2:(nonnull NSString *)key2;
- (nonnull instancetype)initWithEight:(int8_t)eight
sixteen:(int16_t)sixteen
thirtytwo:(int32_t)thirtytwo
sixtyfour:(int64_t)sixtyfour
fthirtytwo:(float)fthirtytwo
fsixtyfour:(double)fsixtyfour
d:(nonnull NSDate *)d
s:(nonnull NSString *)s;
+ (nonnull instancetype)recordWithDerivingsWithEight:(int8_t)eight
sixteen:(int16_t)sixteen
thirtytwo:(int32_t)thirtytwo
sixtyfour:(int64_t)sixtyfour
fthirtytwo:(float)fthirtytwo
fsixtyfour:(double)fsixtyfour
d:(nonnull NSDate *)d
s:(nonnull NSString *)s;
@property (nonatomic, readonly) int32_t key1;
@property (nonatomic, readonly) int8_t eight;
@property (nonatomic, readonly, nonnull) NSString * key2;
@property (nonatomic, readonly) int16_t sixteen;
@property (nonatomic, readonly) int32_t thirtytwo;
@property (nonatomic, readonly) int64_t sixtyfour;
@property (nonatomic, readonly) float fthirtytwo;
@property (nonatomic, readonly) double fsixtyfour;
@property (nonatomic, readonly, nonnull) NSDate * d;
@property (nonatomic, readonly, nonnull) NSString * s;
- (NSComparisonResult)compare:(nonnull DBRecordWithDerivings *)other;
......
......@@ -6,21 +6,45 @@
@implementation DBRecordWithDerivings
- (nonnull instancetype)initWithKey1:(int32_t)key1
key2:(nonnull NSString *)key2
- (nonnull instancetype)initWithEight:(int8_t)eight
sixteen:(int16_t)sixteen
thirtytwo:(int32_t)thirtytwo
sixtyfour:(int64_t)sixtyfour
fthirtytwo:(float)fthirtytwo
fsixtyfour:(double)fsixtyfour
d:(nonnull NSDate *)d
s:(nonnull NSString *)s
{
if (self = [super init]) {
_key1 = key1;
_key2 = [key2 copy];
_eight = eight;
_sixteen = sixteen;
_thirtytwo = thirtytwo;
_sixtyfour = sixtyfour;
_fthirtytwo = fthirtytwo;
_fsixtyfour = fsixtyfour;
_d = d;
_s = [s copy];
}
return self;
}
+ (nonnull instancetype)recordWithDerivingsWithKey1:(int32_t)key1
key2:(nonnull NSString *)key2
+ (nonnull instancetype)recordWithDerivingsWithEight:(int8_t)eight
sixteen:(int16_t)sixteen
thirtytwo:(int32_t)thirtytwo
sixtyfour:(int64_t)sixtyfour
fthirtytwo:(float)fthirtytwo
fsixtyfour:(double)fsixtyfour
d:(nonnull NSDate *)d
s:(nonnull NSString *)s
{
return [[self alloc] initWithKey1:key1
key2:key2];
return [[self alloc] initWithEight:eight
sixteen:sixteen
thirtytwo:thirtytwo
sixtyfour:sixtyfour
fthirtytwo:fthirtytwo
fsixtyfour:fsixtyfour
d:d
s:s];
}
- (BOOL)isEqual:(id)other
......@@ -29,23 +53,35 @@
return NO;
}
DBRecordWithDerivings *typedOther = (DBRecordWithDerivings *)other;
return self.key1 == typedOther.key1 &&
[self.key2 isEqualToString:typedOther.key2];
return self.eight == typedOther.eight &&
self.sixteen == typedOther.sixteen &&
self.thirtytwo == typedOther.thirtytwo &&
self.sixtyfour == typedOther.sixtyfour &&
self.fthirtytwo == typedOther.fthirtytwo &&
self.fsixtyfour == typedOther.fsixtyfour &&
[self.d isEqualToDate:typedOther.d] &&
[self.s isEqualToString:typedOther.s];
}
- (NSUInteger)hash
{
return NSStringFromClass([self class]).hash ^
(NSUInteger)self.key1 ^
self.key2.hash;
(NSUInteger)self.eight ^
(NSUInteger)self.sixteen ^
(NSUInteger)self.thirtytwo ^
(NSUInteger)self.sixtyfour ^
(NSUInteger)self.fthirtytwo ^
(NSUInteger)self.fsixtyfour ^
self.d.hash ^
self.s.hash;
}
- (NSComparisonResult)compare:(DBRecordWithDerivings *)other
{
NSComparisonResult tempResult;
if (self.key1 < other.key1) {
if (self.eight < other.eight) {
tempResult = NSOrderedAscending;
} else if (self.key1 > other.key1) {
} else if (self.eight > other.eight) {
tempResult = NSOrderedDescending;
} else {
tempResult = NSOrderedSame;
......@@ -53,7 +89,61 @@
if (tempResult != NSOrderedSame) {
return tempResult;
}
tempResult = [self.key2 compare:other.key2];
if (self.sixteen < other.sixteen) {
tempResult = NSOrderedAscending;
} else if (self.sixteen > other.sixteen) {
tempResult = NSOrderedDescending;
} else {
tempResult = NSOrderedSame;
}
if (tempResult != NSOrderedSame) {
return tempResult;
}
if (self.thirtytwo < other.thirtytwo) {
tempResult = NSOrderedAscending;
} else if (self.thirtytwo > other.thirtytwo) {
tempResult = NSOrderedDescending;
} else {
tempResult = NSOrderedSame;
}
if (tempResult != NSOrderedSame) {
return tempResult;
}
if (self.sixtyfour < other.sixtyfour) {
tempResult = NSOrderedAscending;
} else if (self.sixtyfour > other.sixtyfour) {
tempResult = NSOrderedDescending;
} else {
tempResult = NSOrderedSame;
}
if (tempResult != NSOrderedSame) {
return tempResult;
}
if (self.fthirtytwo < other.fthirtytwo) {
tempResult = NSOrderedAscending;
} else if (self.fthirtytwo > other.fthirtytwo) {
tempResult = NSOrderedDescending;
} else {
tempResult = NSOrderedSame;
}
if (tempResult != NSOrderedSame) {
return tempResult;
}
if (self.fsixtyfour < other.fsixtyfour) {
tempResult = NSOrderedAscending;
} else if (self.fsixtyfour > other.fsixtyfour) {
tempResult = NSOrderedDescending;
} else {
tempResult = NSOrderedSame;
}
if (tempResult != NSOrderedSame) {
return tempResult;
}
tempResult = [self.d compare:other.d];
if (tempResult != NSOrderedSame) {
return tempResult;
}
tempResult = [self.s compare:other.s];
if (tempResult != NSOrderedSame) {
return tempResult;
}
......@@ -62,7 +152,7 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p key1:%@ key2:%@>", self.class, (void *)self, @(self.key1), self.key2];
return [NSString stringWithFormat:@"<%@ %p eight:%@ sixteen:%@ thirtytwo:%@ sixtyfour:%@ fthirtytwo:%@ fsixtyfour:%@ d:%@ s:%@>", self.class, (void *)self, @(self.eight), @(self.sixteen), @(self.thirtytwo), @(self.sixtyfour), @(self.fthirtytwo), @(self.fsixtyfour), self.d, self.s];
}
@end
......@@ -2,12 +2,18 @@ package com.dropbox.djinni.test;
import junit.framework.TestCase;
import java.util.Date;
public class RecordWithDerivingsTest extends TestCase {
private final RecordWithDerivings record1 = new RecordWithDerivings(1, "String1");
private final RecordWithDerivings record1A = new RecordWithDerivings(1, "String1");
private final RecordWithDerivings record2 = new RecordWithDerivings(1, "String2");
private final RecordWithDerivings record3 = new RecordWithDerivings(2, "String1");
private final RecordWithDerivings record1 = new RecordWithDerivings((byte)1, (short)2, 3, 4, 5.0f, 6.0,
new Date(7), "String8");
private final RecordWithDerivings record1A = new RecordWithDerivings((byte)1, (short)2, 3, 4, 5.0f, 6.0,
new Date(7), "String8");
private final RecordWithDerivings record2 = new RecordWithDerivings((byte)1, (short)2, 3, 4, 5.0f, 6.0,
new Date(7), "String888");
private final RecordWithDerivings record3 = new RecordWithDerivings((byte)111, (short)2, 3, 4, 5.0f, 6.0,
new Date(7), "String8");
public void testRecordOrd() {
assertTrue(record1.compareTo(record1A) == 0);
......
......@@ -3,13 +3,22 @@
#import <XCTest/XCTest.h>
using namespace testsuite;
#import <chrono>
static RecordWithDerivings record1(1, "String1");
static RecordWithDerivings record1A(1, "String1");
static RecordWithDerivings record2(1, "String2");
static RecordWithDerivings record3(2, "String1");
using namespace testsuite;
static RecordWithDerivings record1(1, 2, 3, 4, 5.0f, 6.0,
std::chrono::system_clock::time_point(std::chrono::milliseconds(7)),
"String8");
static RecordWithDerivings record1A(1, 2, 3, 4, 5.0f, 6.0,
std::chrono::system_clock::time_point(std::chrono::milliseconds(7)),
"String8");
static RecordWithDerivings record2(1, 2, 3, 4, 5.0f, 6.0,
std::chrono::system_clock::time_point(std::chrono::milliseconds(7)),
"String8888");
static RecordWithDerivings record3(111, 2, 3, 4, 5.0f, 6.0,
std::chrono::system_clock::time_point(std::chrono::milliseconds(7)),
"String8");
static RecordWithNestedDerivings nestedRecord1(1, record1);
static RecordWithNestedDerivings nestedRecord1A(1, record1A);
static RecordWithNestedDerivings nestedRecord2(1, record2);
......
......@@ -3,10 +3,42 @@
#import <XCTest/XCTest.h>
static DBRecordWithDerivings *record1 = [DBRecordWithDerivings recordWithDerivingsWithKey1:1 key2:@"String1"];
static DBRecordWithDerivings *record1A = [DBRecordWithDerivings recordWithDerivingsWithKey1:1 key2:@"String1"];
static DBRecordWithDerivings *record2 = [DBRecordWithDerivings recordWithDerivingsWithKey1:1 key2:@"String2"];
static DBRecordWithDerivings *record3 = [DBRecordWithDerivings recordWithDerivingsWithKey1:2 key2:@"String1"];
static DBRecordWithDerivings *record1 = [DBRecordWithDerivings
recordWithDerivingsWithEight:1
sixteen:2
thirtytwo:3
sixtyfour:4
fthirtytwo:5.0f
fsixtyfour:6.0
d:[NSDate dateWithTimeIntervalSince1970:7]
s:@"String8"];
static DBRecordWithDerivings *record1A = [DBRecordWithDerivings
recordWithDerivingsWithEight:1
sixteen:2
thirtytwo:3
sixtyfour:4
fthirtytwo:5.0f
fsixtyfour:6.0
d:[NSDate dateWithTimeIntervalSince1970:7]
s:@"String8"];
static DBRecordWithDerivings *record2 = [DBRecordWithDerivings
recordWithDerivingsWithEight:1
sixteen:2
thirtytwo:3
sixtyfour:4
fthirtytwo:5.0f
fsixtyfour:6.0
d:[NSDate dateWithTimeIntervalSince1970:7]
s:@"String888"];
static DBRecordWithDerivings *record3 = [DBRecordWithDerivings
recordWithDerivingsWithEight:111
sixteen:2
thirtytwo:3
sixtyfour:4
fthirtytwo:5.0f
fsixtyfour:6.0
d:[NSDate dateWithTimeIntervalSince1970:7]
s:@"String8"];
static DBRecordWithNestedDerivings *nestedRecord1 = [DBRecordWithNestedDerivings recordWithNestedDerivingsWithKey:1 rec:record1];
static DBRecordWithNestedDerivings *nestedRecord1A = [DBRecordWithNestedDerivings recordWithNestedDerivingsWithKey:1 rec:record1A];
......
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