1ffe3c632Sopenharmony_ci// Protocol Buffers - Google's data interchange format 2ffe3c632Sopenharmony_ci// Copyright 2015 Google Inc. All rights reserved. 3ffe3c632Sopenharmony_ci// https://developers.google.com/protocol-buffers/ 4ffe3c632Sopenharmony_ci// 5ffe3c632Sopenharmony_ci// Redistribution and use in source and binary forms, with or without 6ffe3c632Sopenharmony_ci// modification, are permitted provided that the following conditions are 7ffe3c632Sopenharmony_ci// met: 8ffe3c632Sopenharmony_ci// 9ffe3c632Sopenharmony_ci// * Redistributions of source code must retain the above copyright 10ffe3c632Sopenharmony_ci// notice, this list of conditions and the following disclaimer. 11ffe3c632Sopenharmony_ci// * Redistributions in binary form must reproduce the above 12ffe3c632Sopenharmony_ci// copyright notice, this list of conditions and the following disclaimer 13ffe3c632Sopenharmony_ci// in the documentation and/or other materials provided with the 14ffe3c632Sopenharmony_ci// distribution. 15ffe3c632Sopenharmony_ci// * Neither the name of Google Inc. nor the names of its 16ffe3c632Sopenharmony_ci// contributors may be used to endorse or promote products derived from 17ffe3c632Sopenharmony_ci// this software without specific prior written permission. 18ffe3c632Sopenharmony_ci// 19ffe3c632Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20ffe3c632Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21ffe3c632Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22ffe3c632Sopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23ffe3c632Sopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24ffe3c632Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25ffe3c632Sopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26ffe3c632Sopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27ffe3c632Sopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28ffe3c632Sopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29ffe3c632Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30ffe3c632Sopenharmony_ci 31ffe3c632Sopenharmony_ci#import "GPBTestUtilities.h" 32ffe3c632Sopenharmony_ci 33ffe3c632Sopenharmony_ci#import <objc/runtime.h> 34ffe3c632Sopenharmony_ci 35ffe3c632Sopenharmony_ci#import "GPBMessage.h" 36ffe3c632Sopenharmony_ci 37ffe3c632Sopenharmony_ci#import "google/protobuf/MapUnittest.pbobjc.h" 38ffe3c632Sopenharmony_ci#import "google/protobuf/Unittest.pbobjc.h" 39ffe3c632Sopenharmony_ci#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h" 40ffe3c632Sopenharmony_ci#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" 41ffe3c632Sopenharmony_ci#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h" 42ffe3c632Sopenharmony_ci 43ffe3c632Sopenharmony_ci@interface MessageMergeTests : GPBTestCase 44ffe3c632Sopenharmony_ci@end 45ffe3c632Sopenharmony_ci 46ffe3c632Sopenharmony_ci@implementation MessageMergeTests 47ffe3c632Sopenharmony_ci 48ffe3c632Sopenharmony_ci// TODO(thomasvl): Pull tests over from GPBMessageTests that are merge specific. 49ffe3c632Sopenharmony_ci 50ffe3c632Sopenharmony_ci- (void)testProto3MergingAndZeroValues { 51ffe3c632Sopenharmony_ci // Proto2 covered in other tests. 52ffe3c632Sopenharmony_ci 53ffe3c632Sopenharmony_ci Message3 *src = [[Message3 alloc] init]; 54ffe3c632Sopenharmony_ci Message3 *dst = [[Message3 alloc] init]; 55ffe3c632Sopenharmony_ci NSData *testData1 = [@"abc" dataUsingEncoding:NSUTF8StringEncoding]; 56ffe3c632Sopenharmony_ci NSData *testData2 = [@"def" dataUsingEncoding:NSUTF8StringEncoding]; 57ffe3c632Sopenharmony_ci 58ffe3c632Sopenharmony_ci dst.optionalInt32 = 1; 59ffe3c632Sopenharmony_ci dst.optionalInt64 = 1; 60ffe3c632Sopenharmony_ci dst.optionalUint32 = 1; 61ffe3c632Sopenharmony_ci dst.optionalUint64 = 1; 62ffe3c632Sopenharmony_ci dst.optionalSint32 = 1; 63ffe3c632Sopenharmony_ci dst.optionalSint64 = 1; 64ffe3c632Sopenharmony_ci dst.optionalFixed32 = 1; 65ffe3c632Sopenharmony_ci dst.optionalFixed64 = 1; 66ffe3c632Sopenharmony_ci dst.optionalSfixed32 = 1; 67ffe3c632Sopenharmony_ci dst.optionalSfixed64 = 1; 68ffe3c632Sopenharmony_ci dst.optionalFloat = 1.0f; 69ffe3c632Sopenharmony_ci dst.optionalDouble = 1.0; 70ffe3c632Sopenharmony_ci dst.optionalBool = YES; 71ffe3c632Sopenharmony_ci dst.optionalString = @"bar"; 72ffe3c632Sopenharmony_ci dst.optionalBytes = testData1; 73ffe3c632Sopenharmony_ci dst.optionalEnum = Message3_Enum_Bar; 74ffe3c632Sopenharmony_ci 75ffe3c632Sopenharmony_ci // All zeros, nothing should overright. 76ffe3c632Sopenharmony_ci 77ffe3c632Sopenharmony_ci src.optionalInt32 = 0; 78ffe3c632Sopenharmony_ci src.optionalInt64 = 0; 79ffe3c632Sopenharmony_ci src.optionalUint32 = 0; 80ffe3c632Sopenharmony_ci src.optionalUint64 = 0; 81ffe3c632Sopenharmony_ci src.optionalSint32 = 0; 82ffe3c632Sopenharmony_ci src.optionalSint64 = 0; 83ffe3c632Sopenharmony_ci src.optionalFixed32 = 0; 84ffe3c632Sopenharmony_ci src.optionalFixed64 = 0; 85ffe3c632Sopenharmony_ci src.optionalSfixed32 = 0; 86ffe3c632Sopenharmony_ci src.optionalSfixed64 = 0; 87ffe3c632Sopenharmony_ci src.optionalFloat = 0.0f; 88ffe3c632Sopenharmony_ci src.optionalDouble = 0.0; 89ffe3c632Sopenharmony_ci src.optionalBool = NO; 90ffe3c632Sopenharmony_ci src.optionalString = @""; 91ffe3c632Sopenharmony_ci src.optionalBytes = [NSData data]; 92ffe3c632Sopenharmony_ci src.optionalEnum = Message3_Enum_Foo; // first value 93ffe3c632Sopenharmony_ci 94ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 95ffe3c632Sopenharmony_ci 96ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalInt32, 1); 97ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalInt64, 1); 98ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalUint32, 1U); 99ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalUint64, 1U); 100ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSint32, 1); 101ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSint64, 1); 102ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFixed32, 1U); 103ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFixed64, 1U); 104ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSfixed32, 1); 105ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSfixed64, 1); 106ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFloat, 1.0f); 107ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalDouble, 1.0); 108ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalBool, YES); 109ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.optionalString, @"bar"); 110ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.optionalBytes, testData1); 111ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalEnum, Message3_Enum_Bar); 112ffe3c632Sopenharmony_ci 113ffe3c632Sopenharmony_ci // Half the values that will replace. 114ffe3c632Sopenharmony_ci 115ffe3c632Sopenharmony_ci src.optionalInt32 = 0; 116ffe3c632Sopenharmony_ci src.optionalInt64 = 2; 117ffe3c632Sopenharmony_ci src.optionalUint32 = 0; 118ffe3c632Sopenharmony_ci src.optionalUint64 = 2; 119ffe3c632Sopenharmony_ci src.optionalSint32 = 0; 120ffe3c632Sopenharmony_ci src.optionalSint64 = 2; 121ffe3c632Sopenharmony_ci src.optionalFixed32 = 0; 122ffe3c632Sopenharmony_ci src.optionalFixed64 = 2; 123ffe3c632Sopenharmony_ci src.optionalSfixed32 = 0; 124ffe3c632Sopenharmony_ci src.optionalSfixed64 = 2; 125ffe3c632Sopenharmony_ci src.optionalFloat = 0.0f; 126ffe3c632Sopenharmony_ci src.optionalDouble = 2.0; 127ffe3c632Sopenharmony_ci src.optionalBool = YES; // No other value to use. :( 128ffe3c632Sopenharmony_ci src.optionalString = @"baz"; 129ffe3c632Sopenharmony_ci src.optionalBytes = nil; 130ffe3c632Sopenharmony_ci src.optionalEnum = Message3_Enum_Baz; 131ffe3c632Sopenharmony_ci 132ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 133ffe3c632Sopenharmony_ci 134ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalInt32, 1); 135ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalInt64, 2); 136ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalUint32, 1U); 137ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalUint64, 2U); 138ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSint32, 1); 139ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSint64, 2); 140ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFixed32, 1U); 141ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFixed64, 2U); 142ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSfixed32, 1); 143ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSfixed64, 2); 144ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFloat, 1.0f); 145ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalDouble, 2.0); 146ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalBool, YES); 147ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.optionalString, @"baz"); 148ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.optionalBytes, testData1); 149ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalEnum, Message3_Enum_Baz); 150ffe3c632Sopenharmony_ci 151ffe3c632Sopenharmony_ci // Other half the values that will replace. 152ffe3c632Sopenharmony_ci 153ffe3c632Sopenharmony_ci src.optionalInt32 = 3; 154ffe3c632Sopenharmony_ci src.optionalInt64 = 0; 155ffe3c632Sopenharmony_ci src.optionalUint32 = 3; 156ffe3c632Sopenharmony_ci src.optionalUint64 = 0; 157ffe3c632Sopenharmony_ci src.optionalSint32 = 3; 158ffe3c632Sopenharmony_ci src.optionalSint64 = 0; 159ffe3c632Sopenharmony_ci src.optionalFixed32 = 3; 160ffe3c632Sopenharmony_ci src.optionalFixed64 = 0; 161ffe3c632Sopenharmony_ci src.optionalSfixed32 = 3; 162ffe3c632Sopenharmony_ci src.optionalSfixed64 = 0; 163ffe3c632Sopenharmony_ci src.optionalFloat = 3.0f; 164ffe3c632Sopenharmony_ci src.optionalDouble = 0.0; 165ffe3c632Sopenharmony_ci src.optionalBool = YES; // No other value to use. :( 166ffe3c632Sopenharmony_ci src.optionalString = nil; 167ffe3c632Sopenharmony_ci src.optionalBytes = testData2; 168ffe3c632Sopenharmony_ci src.optionalEnum = Message3_Enum_Foo; 169ffe3c632Sopenharmony_ci 170ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 171ffe3c632Sopenharmony_ci 172ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalInt32, 3); 173ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalInt64, 2); 174ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalUint32, 3U); 175ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalUint64, 2U); 176ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSint32, 3); 177ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSint64, 2); 178ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFixed32, 3U); 179ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFixed64, 2U); 180ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSfixed32, 3); 181ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalSfixed64, 2); 182ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalFloat, 3.0f); 183ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalDouble, 2.0); 184ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalBool, YES); 185ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.optionalString, @"baz"); 186ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.optionalBytes, testData2); 187ffe3c632Sopenharmony_ci XCTAssertEqual(dst.optionalEnum, Message3_Enum_Baz); 188ffe3c632Sopenharmony_ci 189ffe3c632Sopenharmony_ci [src release]; 190ffe3c632Sopenharmony_ci [dst release]; 191ffe3c632Sopenharmony_ci} 192ffe3c632Sopenharmony_ci 193ffe3c632Sopenharmony_ci- (void)testProto3MergingEnums { 194ffe3c632Sopenharmony_ci UnknownEnumsMyMessage *src = [UnknownEnumsMyMessage message]; 195ffe3c632Sopenharmony_ci UnknownEnumsMyMessage *dst = [UnknownEnumsMyMessage message]; 196ffe3c632Sopenharmony_ci 197ffe3c632Sopenharmony_ci // Known value. 198ffe3c632Sopenharmony_ci 199ffe3c632Sopenharmony_ci src.e = UnknownEnumsMyEnum_Bar; 200ffe3c632Sopenharmony_ci src.repeatedEArray = 201ffe3c632Sopenharmony_ci [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue 202ffe3c632Sopenharmony_ci rawValue:UnknownEnumsMyEnum_Bar]; 203ffe3c632Sopenharmony_ci src.repeatedPackedEArray = 204ffe3c632Sopenharmony_ci [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue 205ffe3c632Sopenharmony_ci rawValue:UnknownEnumsMyEnum_Bar]; 206ffe3c632Sopenharmony_ci src.oneofE1 = UnknownEnumsMyEnum_Bar; 207ffe3c632Sopenharmony_ci 208ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 209ffe3c632Sopenharmony_ci 210ffe3c632Sopenharmony_ci XCTAssertEqual(dst.e, UnknownEnumsMyEnum_Bar); 211ffe3c632Sopenharmony_ci XCTAssertEqual(dst.repeatedEArray.count, 1U); 212ffe3c632Sopenharmony_ci XCTAssertEqual([dst.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar); 213ffe3c632Sopenharmony_ci XCTAssertEqual(dst.repeatedPackedEArray.count, 1U); 214ffe3c632Sopenharmony_ci XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0], 215ffe3c632Sopenharmony_ci UnknownEnumsMyEnum_Bar); 216ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofE1, UnknownEnumsMyEnum_Bar); 217ffe3c632Sopenharmony_ci 218ffe3c632Sopenharmony_ci // Unknown value. 219ffe3c632Sopenharmony_ci 220ffe3c632Sopenharmony_ci const int32_t kUnknownValue = 666; 221ffe3c632Sopenharmony_ci 222ffe3c632Sopenharmony_ci SetUnknownEnumsMyMessage_E_RawValue(src, kUnknownValue); 223ffe3c632Sopenharmony_ci src.repeatedEArray = 224ffe3c632Sopenharmony_ci [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue 225ffe3c632Sopenharmony_ci rawValue:kUnknownValue]; 226ffe3c632Sopenharmony_ci src.repeatedPackedEArray = 227ffe3c632Sopenharmony_ci [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue 228ffe3c632Sopenharmony_ci rawValue:kUnknownValue]; 229ffe3c632Sopenharmony_ci SetUnknownEnumsMyMessage_OneofE1_RawValue(src, kUnknownValue); 230ffe3c632Sopenharmony_ci 231ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 232ffe3c632Sopenharmony_ci 233ffe3c632Sopenharmony_ci XCTAssertEqual(dst.e, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); 234ffe3c632Sopenharmony_ci XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(dst), kUnknownValue); 235ffe3c632Sopenharmony_ci XCTAssertEqual(dst.repeatedEArray.count, 2U); 236ffe3c632Sopenharmony_ci XCTAssertEqual([dst.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar); 237ffe3c632Sopenharmony_ci XCTAssertEqual([dst.repeatedEArray valueAtIndex:1], 238ffe3c632Sopenharmony_ci UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); 239ffe3c632Sopenharmony_ci XCTAssertEqual([dst.repeatedEArray rawValueAtIndex:1], kUnknownValue); 240ffe3c632Sopenharmony_ci XCTAssertEqual(dst.repeatedPackedEArray.count, 2U); 241ffe3c632Sopenharmony_ci XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0], 242ffe3c632Sopenharmony_ci UnknownEnumsMyEnum_Bar); 243ffe3c632Sopenharmony_ci XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:1], 244ffe3c632Sopenharmony_ci UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); 245ffe3c632Sopenharmony_ci XCTAssertEqual([dst.repeatedPackedEArray rawValueAtIndex:1], kUnknownValue); 246ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofE1, 247ffe3c632Sopenharmony_ci UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); 248ffe3c632Sopenharmony_ci XCTAssertEqual(UnknownEnumsMyMessage_OneofE1_RawValue(dst), kUnknownValue); 249ffe3c632Sopenharmony_ci} 250ffe3c632Sopenharmony_ci 251ffe3c632Sopenharmony_ci- (void)testProto2MergeOneof { 252ffe3c632Sopenharmony_ci Message2 *src = [Message2 message]; 253ffe3c632Sopenharmony_ci Message2 *dst = [Message2 message]; 254ffe3c632Sopenharmony_ci 255ffe3c632Sopenharmony_ci // 256ffe3c632Sopenharmony_ci // Make sure whatever is in dst gets cleared out be merging in something else. 257ffe3c632Sopenharmony_ci // 258ffe3c632Sopenharmony_ci 259ffe3c632Sopenharmony_ci dst.oneofEnum = Message2_Enum_Bar; 260ffe3c632Sopenharmony_ci 261ffe3c632Sopenharmony_ci//%PDDM-DEFINE MERGE2_TEST(SET_NAME, SET_VALUE, CLEARED_NAME, CLEARED_DEFAULT) 262ffe3c632Sopenharmony_ci//% src.oneof##SET_NAME = SET_VALUE; 263ffe3c632Sopenharmony_ci//% [dst mergeFrom:src]; 264ffe3c632Sopenharmony_ci//% XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_Oneof##SET_NAME); 265ffe3c632Sopenharmony_ci//% XCTAssertEqual(dst.oneof##SET_NAME, SET_VALUE); 266ffe3c632Sopenharmony_ci//% XCTAssertEqual(dst.oneof##CLEARED_NAME, CLEARED_DEFAULT); 267ffe3c632Sopenharmony_ci//% 268ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Int32, 10, Enum, Message2_Enum_Baz) 269ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 270ffe3c632Sopenharmony_ci// clang-format off 271ffe3c632Sopenharmony_ci 272ffe3c632Sopenharmony_ci src.oneofInt32 = 10; 273ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 274ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt32); 275ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofInt32, 10); 276ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofEnum, Message2_Enum_Baz); 277ffe3c632Sopenharmony_ci 278ffe3c632Sopenharmony_ci// clang-format on 279ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Int64, 11, Int32, 100) 280ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 281ffe3c632Sopenharmony_ci// clang-format off 282ffe3c632Sopenharmony_ci 283ffe3c632Sopenharmony_ci src.oneofInt64 = 11; 284ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 285ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt64); 286ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofInt64, 11); 287ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofInt32, 100); 288ffe3c632Sopenharmony_ci 289ffe3c632Sopenharmony_ci// clang-format on 290ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Uint32, 12U, Int64, 101) 291ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 292ffe3c632Sopenharmony_ci// clang-format off 293ffe3c632Sopenharmony_ci 294ffe3c632Sopenharmony_ci src.oneofUint32 = 12U; 295ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 296ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofUint32); 297ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofUint32, 12U); 298ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofInt64, 101); 299ffe3c632Sopenharmony_ci 300ffe3c632Sopenharmony_ci// clang-format on 301ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Uint64, 13U, Uint32, 102U) 302ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 303ffe3c632Sopenharmony_ci// clang-format off 304ffe3c632Sopenharmony_ci 305ffe3c632Sopenharmony_ci src.oneofUint64 = 13U; 306ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 307ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofUint64); 308ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofUint64, 13U); 309ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofUint32, 102U); 310ffe3c632Sopenharmony_ci 311ffe3c632Sopenharmony_ci// clang-format on 312ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Sint32, 14, Uint64, 103U) 313ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 314ffe3c632Sopenharmony_ci// clang-format off 315ffe3c632Sopenharmony_ci 316ffe3c632Sopenharmony_ci src.oneofSint32 = 14; 317ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 318ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSint32); 319ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSint32, 14); 320ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofUint64, 103U); 321ffe3c632Sopenharmony_ci 322ffe3c632Sopenharmony_ci// clang-format on 323ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Sint64, 15, Sint32, 104) 324ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 325ffe3c632Sopenharmony_ci// clang-format off 326ffe3c632Sopenharmony_ci 327ffe3c632Sopenharmony_ci src.oneofSint64 = 15; 328ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 329ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSint64); 330ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSint64, 15); 331ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSint32, 104); 332ffe3c632Sopenharmony_ci 333ffe3c632Sopenharmony_ci// clang-format on 334ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Fixed32, 16U, Sint64, 105) 335ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 336ffe3c632Sopenharmony_ci// clang-format off 337ffe3c632Sopenharmony_ci 338ffe3c632Sopenharmony_ci src.oneofFixed32 = 16U; 339ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 340ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFixed32); 341ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFixed32, 16U); 342ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSint64, 105); 343ffe3c632Sopenharmony_ci 344ffe3c632Sopenharmony_ci// clang-format on 345ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Fixed64, 17U, Fixed32, 106U) 346ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 347ffe3c632Sopenharmony_ci// clang-format off 348ffe3c632Sopenharmony_ci 349ffe3c632Sopenharmony_ci src.oneofFixed64 = 17U; 350ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 351ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFixed64); 352ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFixed64, 17U); 353ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFixed32, 106U); 354ffe3c632Sopenharmony_ci 355ffe3c632Sopenharmony_ci// clang-format on 356ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Sfixed32, 18, Fixed64, 107U) 357ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 358ffe3c632Sopenharmony_ci// clang-format off 359ffe3c632Sopenharmony_ci 360ffe3c632Sopenharmony_ci src.oneofSfixed32 = 18; 361ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 362ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32); 363ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSfixed32, 18); 364ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFixed64, 107U); 365ffe3c632Sopenharmony_ci 366ffe3c632Sopenharmony_ci// clang-format on 367ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Sfixed64, 19, Sfixed32, 108) 368ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 369ffe3c632Sopenharmony_ci// clang-format off 370ffe3c632Sopenharmony_ci 371ffe3c632Sopenharmony_ci src.oneofSfixed64 = 19; 372ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 373ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64); 374ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSfixed64, 19); 375ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSfixed32, 108); 376ffe3c632Sopenharmony_ci 377ffe3c632Sopenharmony_ci// clang-format on 378ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Float, 20.0f, Sfixed64, 109) 379ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 380ffe3c632Sopenharmony_ci// clang-format off 381ffe3c632Sopenharmony_ci 382ffe3c632Sopenharmony_ci src.oneofFloat = 20.0f; 383ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 384ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFloat); 385ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFloat, 20.0f); 386ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSfixed64, 109); 387ffe3c632Sopenharmony_ci 388ffe3c632Sopenharmony_ci// clang-format on 389ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Double, 21.0, Float, 110.0f) 390ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 391ffe3c632Sopenharmony_ci// clang-format off 392ffe3c632Sopenharmony_ci 393ffe3c632Sopenharmony_ci src.oneofDouble = 21.0; 394ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 395ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofDouble); 396ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofDouble, 21.0); 397ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFloat, 110.0f); 398ffe3c632Sopenharmony_ci 399ffe3c632Sopenharmony_ci// clang-format on 400ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Bool, NO, Double, 111.0) 401ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 402ffe3c632Sopenharmony_ci// clang-format off 403ffe3c632Sopenharmony_ci 404ffe3c632Sopenharmony_ci src.oneofBool = NO; 405ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 406ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofBool); 407ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofBool, NO); 408ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofDouble, 111.0); 409ffe3c632Sopenharmony_ci 410ffe3c632Sopenharmony_ci// clang-format on 411ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE2_TEST(Enum, Message2_Enum_Bar, Bool, YES) 412ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 413ffe3c632Sopenharmony_ci// clang-format off 414ffe3c632Sopenharmony_ci 415ffe3c632Sopenharmony_ci src.oneofEnum = Message2_Enum_Bar; 416ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 417ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofEnum); 418ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofEnum, Message2_Enum_Bar); 419ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofBool, YES); 420ffe3c632Sopenharmony_ci 421ffe3c632Sopenharmony_ci// clang-format on 422ffe3c632Sopenharmony_ci//%PDDM-EXPAND-END (14 expansions) 423ffe3c632Sopenharmony_ci 424ffe3c632Sopenharmony_ci NSString *oneofStringDefault = @"string"; 425ffe3c632Sopenharmony_ci NSData *oneofBytesDefault = [@"data" dataUsingEncoding:NSUTF8StringEncoding]; 426ffe3c632Sopenharmony_ci 427ffe3c632Sopenharmony_ci src.oneofString = @"foo"; 428ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 429ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofString); 430ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.oneofString, @"foo"); 431ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofEnum, Message2_Enum_Baz); 432ffe3c632Sopenharmony_ci 433ffe3c632Sopenharmony_ci src.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding]; 434ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 435ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofBytes); 436ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.oneofBytes, 437ffe3c632Sopenharmony_ci [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); 438ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.oneofString, oneofStringDefault); 439ffe3c632Sopenharmony_ci 440ffe3c632Sopenharmony_ci Message2_OneofGroup *group = [Message2_OneofGroup message]; 441ffe3c632Sopenharmony_ci group.a = 666; 442ffe3c632Sopenharmony_ci src.oneofGroup = group; 443ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 444ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofGroup); 445ffe3c632Sopenharmony_ci Message2_OneofGroup *mergedGroup = [[dst.oneofGroup retain] autorelease]; 446ffe3c632Sopenharmony_ci XCTAssertNotNil(mergedGroup); 447ffe3c632Sopenharmony_ci XCTAssertNotEqual(mergedGroup, group); // Pointer comparison. 448ffe3c632Sopenharmony_ci XCTAssertEqualObjects(mergedGroup, group); 449ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.oneofBytes, oneofBytesDefault); 450ffe3c632Sopenharmony_ci 451ffe3c632Sopenharmony_ci Message2 *subMessage = [Message2 message]; 452ffe3c632Sopenharmony_ci subMessage.optionalInt32 = 777; 453ffe3c632Sopenharmony_ci src.oneofMessage = subMessage; 454ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 455ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofMessage); 456ffe3c632Sopenharmony_ci Message2 *mergedSubMessage = [[dst.oneofMessage retain] autorelease]; 457ffe3c632Sopenharmony_ci XCTAssertNotNil(mergedSubMessage); 458ffe3c632Sopenharmony_ci XCTAssertNotEqual(mergedSubMessage, subMessage); // Pointer comparison. 459ffe3c632Sopenharmony_ci XCTAssertEqualObjects(mergedSubMessage, subMessage); 460ffe3c632Sopenharmony_ci XCTAssertNotNil(dst.oneofGroup); 461ffe3c632Sopenharmony_ci XCTAssertNotEqual(dst.oneofGroup, mergedGroup); // Pointer comparison. 462ffe3c632Sopenharmony_ci 463ffe3c632Sopenharmony_ci // Back to something else to make sure message clears out ok. 464ffe3c632Sopenharmony_ci 465ffe3c632Sopenharmony_ci src.oneofInt32 = 10; 466ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 467ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt32); 468ffe3c632Sopenharmony_ci XCTAssertNotNil(dst.oneofMessage); 469ffe3c632Sopenharmony_ci XCTAssertNotEqual(dst.oneofMessage, 470ffe3c632Sopenharmony_ci mergedSubMessage); // Pointer comparison. 471ffe3c632Sopenharmony_ci 472ffe3c632Sopenharmony_ci // 473ffe3c632Sopenharmony_ci // Test merging in to message/group when they already had something. 474ffe3c632Sopenharmony_ci // 475ffe3c632Sopenharmony_ci 476ffe3c632Sopenharmony_ci src.oneofGroup = group; 477ffe3c632Sopenharmony_ci mergedGroup = [Message2_OneofGroup message]; 478ffe3c632Sopenharmony_ci mergedGroup.b = 888; 479ffe3c632Sopenharmony_ci dst.oneofGroup = mergedGroup; 480ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 481ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofGroup); 482ffe3c632Sopenharmony_ci // Shouldn't have been a new object. 483ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofGroup, mergedGroup); // Pointer comparison. 484ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofGroup.a, 666); // Pointer comparison. 485ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofGroup.b, 888); // Pointer comparison. 486ffe3c632Sopenharmony_ci 487ffe3c632Sopenharmony_ci src.oneofMessage = subMessage; 488ffe3c632Sopenharmony_ci mergedSubMessage = [Message2 message]; 489ffe3c632Sopenharmony_ci mergedSubMessage.optionalInt64 = 999; 490ffe3c632Sopenharmony_ci dst.oneofMessage = mergedSubMessage; 491ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 492ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofMessage); 493ffe3c632Sopenharmony_ci // Shouldn't have been a new object. 494ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofMessage, mergedSubMessage); // Pointer comparison. 495ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofMessage.optionalInt32, 777); // Pointer comparison. 496ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofMessage.optionalInt64, 999); // Pointer comparison. 497ffe3c632Sopenharmony_ci} 498ffe3c632Sopenharmony_ci 499ffe3c632Sopenharmony_ci- (void)testProto3MergeOneof { 500ffe3c632Sopenharmony_ci Message3 *src = [Message3 message]; 501ffe3c632Sopenharmony_ci Message3 *dst = [Message3 message]; 502ffe3c632Sopenharmony_ci 503ffe3c632Sopenharmony_ci // 504ffe3c632Sopenharmony_ci // Make sure whatever is in dst gets cleared out be merging in something else. 505ffe3c632Sopenharmony_ci // 506ffe3c632Sopenharmony_ci 507ffe3c632Sopenharmony_ci dst.oneofEnum = Message3_Enum_Bar; 508ffe3c632Sopenharmony_ci 509ffe3c632Sopenharmony_ci//%PDDM-DEFINE MERGE3_TEST(SET_NAME, SET_VALUE, CLEARED_NAME, CLEARED_DEFAULT) 510ffe3c632Sopenharmony_ci//% src.oneof##SET_NAME = SET_VALUE; 511ffe3c632Sopenharmony_ci//% [dst mergeFrom:src]; 512ffe3c632Sopenharmony_ci//% XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_Oneof##SET_NAME); 513ffe3c632Sopenharmony_ci//% XCTAssertEqual(dst.oneof##SET_NAME, SET_VALUE); 514ffe3c632Sopenharmony_ci//% XCTAssertEqual(dst.oneof##CLEARED_NAME, CLEARED_DEFAULT); 515ffe3c632Sopenharmony_ci//% 516ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Int32, 10, Enum, Message3_Enum_Foo) 517ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 518ffe3c632Sopenharmony_ci// clang-format off 519ffe3c632Sopenharmony_ci 520ffe3c632Sopenharmony_ci src.oneofInt32 = 10; 521ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 522ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt32); 523ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofInt32, 10); 524ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofEnum, Message3_Enum_Foo); 525ffe3c632Sopenharmony_ci 526ffe3c632Sopenharmony_ci// clang-format on 527ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Int64, 11, Int32, 0) 528ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 529ffe3c632Sopenharmony_ci// clang-format off 530ffe3c632Sopenharmony_ci 531ffe3c632Sopenharmony_ci src.oneofInt64 = 11; 532ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 533ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt64); 534ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofInt64, 11); 535ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofInt32, 0); 536ffe3c632Sopenharmony_ci 537ffe3c632Sopenharmony_ci// clang-format on 538ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Uint32, 12U, Int64, 0) 539ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 540ffe3c632Sopenharmony_ci// clang-format off 541ffe3c632Sopenharmony_ci 542ffe3c632Sopenharmony_ci src.oneofUint32 = 12U; 543ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 544ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofUint32); 545ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofUint32, 12U); 546ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofInt64, 0); 547ffe3c632Sopenharmony_ci 548ffe3c632Sopenharmony_ci// clang-format on 549ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Uint64, 13U, Uint32, 0U) 550ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 551ffe3c632Sopenharmony_ci// clang-format off 552ffe3c632Sopenharmony_ci 553ffe3c632Sopenharmony_ci src.oneofUint64 = 13U; 554ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 555ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofUint64); 556ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofUint64, 13U); 557ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofUint32, 0U); 558ffe3c632Sopenharmony_ci 559ffe3c632Sopenharmony_ci// clang-format on 560ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Sint32, 14, Uint64, 0U) 561ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 562ffe3c632Sopenharmony_ci// clang-format off 563ffe3c632Sopenharmony_ci 564ffe3c632Sopenharmony_ci src.oneofSint32 = 14; 565ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 566ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSint32); 567ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSint32, 14); 568ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofUint64, 0U); 569ffe3c632Sopenharmony_ci 570ffe3c632Sopenharmony_ci// clang-format on 571ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Sint64, 15, Sint32, 0) 572ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 573ffe3c632Sopenharmony_ci// clang-format off 574ffe3c632Sopenharmony_ci 575ffe3c632Sopenharmony_ci src.oneofSint64 = 15; 576ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 577ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSint64); 578ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSint64, 15); 579ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSint32, 0); 580ffe3c632Sopenharmony_ci 581ffe3c632Sopenharmony_ci// clang-format on 582ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Fixed32, 16U, Sint64, 0) 583ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 584ffe3c632Sopenharmony_ci// clang-format off 585ffe3c632Sopenharmony_ci 586ffe3c632Sopenharmony_ci src.oneofFixed32 = 16U; 587ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 588ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFixed32); 589ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFixed32, 16U); 590ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSint64, 0); 591ffe3c632Sopenharmony_ci 592ffe3c632Sopenharmony_ci// clang-format on 593ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Fixed64, 17U, Fixed32, 0U) 594ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 595ffe3c632Sopenharmony_ci// clang-format off 596ffe3c632Sopenharmony_ci 597ffe3c632Sopenharmony_ci src.oneofFixed64 = 17U; 598ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 599ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFixed64); 600ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFixed64, 17U); 601ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFixed32, 0U); 602ffe3c632Sopenharmony_ci 603ffe3c632Sopenharmony_ci// clang-format on 604ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Sfixed32, 18, Fixed64, 0U) 605ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 606ffe3c632Sopenharmony_ci// clang-format off 607ffe3c632Sopenharmony_ci 608ffe3c632Sopenharmony_ci src.oneofSfixed32 = 18; 609ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 610ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32); 611ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSfixed32, 18); 612ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFixed64, 0U); 613ffe3c632Sopenharmony_ci 614ffe3c632Sopenharmony_ci// clang-format on 615ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Sfixed64, 19, Sfixed32, 0) 616ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 617ffe3c632Sopenharmony_ci// clang-format off 618ffe3c632Sopenharmony_ci 619ffe3c632Sopenharmony_ci src.oneofSfixed64 = 19; 620ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 621ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64); 622ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSfixed64, 19); 623ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSfixed32, 0); 624ffe3c632Sopenharmony_ci 625ffe3c632Sopenharmony_ci// clang-format on 626ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Float, 20.0f, Sfixed64, 0) 627ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 628ffe3c632Sopenharmony_ci// clang-format off 629ffe3c632Sopenharmony_ci 630ffe3c632Sopenharmony_ci src.oneofFloat = 20.0f; 631ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 632ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFloat); 633ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFloat, 20.0f); 634ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofSfixed64, 0); 635ffe3c632Sopenharmony_ci 636ffe3c632Sopenharmony_ci// clang-format on 637ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Double, 21.0, Float, 0.0f) 638ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 639ffe3c632Sopenharmony_ci// clang-format off 640ffe3c632Sopenharmony_ci 641ffe3c632Sopenharmony_ci src.oneofDouble = 21.0; 642ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 643ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofDouble); 644ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofDouble, 21.0); 645ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofFloat, 0.0f); 646ffe3c632Sopenharmony_ci 647ffe3c632Sopenharmony_ci// clang-format on 648ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Bool, YES, Double, 0.0) 649ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 650ffe3c632Sopenharmony_ci// clang-format off 651ffe3c632Sopenharmony_ci 652ffe3c632Sopenharmony_ci src.oneofBool = YES; 653ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 654ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofBool); 655ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofBool, YES); 656ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofDouble, 0.0); 657ffe3c632Sopenharmony_ci 658ffe3c632Sopenharmony_ci// clang-format on 659ffe3c632Sopenharmony_ci//%PDDM-EXPAND MERGE3_TEST(Enum, Message3_Enum_Bar, Bool, NO) 660ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 661ffe3c632Sopenharmony_ci// clang-format off 662ffe3c632Sopenharmony_ci 663ffe3c632Sopenharmony_ci src.oneofEnum = Message3_Enum_Bar; 664ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 665ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofEnum); 666ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofEnum, Message3_Enum_Bar); 667ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofBool, NO); 668ffe3c632Sopenharmony_ci 669ffe3c632Sopenharmony_ci// clang-format on 670ffe3c632Sopenharmony_ci//%PDDM-EXPAND-END (14 expansions) 671ffe3c632Sopenharmony_ci 672ffe3c632Sopenharmony_ci NSString *oneofStringDefault = @""; 673ffe3c632Sopenharmony_ci NSData *oneofBytesDefault = [NSData data]; 674ffe3c632Sopenharmony_ci 675ffe3c632Sopenharmony_ci src.oneofString = @"foo"; 676ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 677ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofString); 678ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.oneofString, @"foo"); 679ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofEnum, Message3_Enum_Foo); 680ffe3c632Sopenharmony_ci 681ffe3c632Sopenharmony_ci src.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding]; 682ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 683ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofBytes); 684ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.oneofBytes, 685ffe3c632Sopenharmony_ci [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); 686ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.oneofString, oneofStringDefault); 687ffe3c632Sopenharmony_ci 688ffe3c632Sopenharmony_ci 689ffe3c632Sopenharmony_ci Message3 *subMessage = [Message3 message]; 690ffe3c632Sopenharmony_ci subMessage.optionalInt32 = 777; 691ffe3c632Sopenharmony_ci src.oneofMessage = subMessage; 692ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 693ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofMessage); 694ffe3c632Sopenharmony_ci Message3 *mergedSubMessage = [[dst.oneofMessage retain] autorelease]; 695ffe3c632Sopenharmony_ci XCTAssertNotNil(mergedSubMessage); 696ffe3c632Sopenharmony_ci XCTAssertNotEqual(mergedSubMessage, subMessage); // Pointer comparison. 697ffe3c632Sopenharmony_ci XCTAssertEqualObjects(mergedSubMessage, subMessage); 698ffe3c632Sopenharmony_ci XCTAssertEqualObjects(dst.oneofBytes, oneofBytesDefault); 699ffe3c632Sopenharmony_ci 700ffe3c632Sopenharmony_ci // Back to something else to make sure message clears out ok. 701ffe3c632Sopenharmony_ci 702ffe3c632Sopenharmony_ci src.oneofInt32 = 10; 703ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 704ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt32); 705ffe3c632Sopenharmony_ci XCTAssertNotNil(dst.oneofMessage); 706ffe3c632Sopenharmony_ci XCTAssertNotEqual(dst.oneofMessage, 707ffe3c632Sopenharmony_ci mergedSubMessage); // Pointer comparison. 708ffe3c632Sopenharmony_ci 709ffe3c632Sopenharmony_ci // 710ffe3c632Sopenharmony_ci // Test merging in to message when they already had something. 711ffe3c632Sopenharmony_ci // 712ffe3c632Sopenharmony_ci 713ffe3c632Sopenharmony_ci src.oneofMessage = subMessage; 714ffe3c632Sopenharmony_ci mergedSubMessage = [Message3 message]; 715ffe3c632Sopenharmony_ci mergedSubMessage.optionalInt64 = 999; 716ffe3c632Sopenharmony_ci dst.oneofMessage = mergedSubMessage; 717ffe3c632Sopenharmony_ci [dst mergeFrom:src]; 718ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofMessage); 719ffe3c632Sopenharmony_ci // Shouldn't have been a new object. 720ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofMessage, mergedSubMessage); // Pointer comparison. 721ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofMessage.optionalInt32, 777); // Pointer comparison. 722ffe3c632Sopenharmony_ci XCTAssertEqual(dst.oneofMessage.optionalInt64, 999); // Pointer comparison. 723ffe3c632Sopenharmony_ci} 724ffe3c632Sopenharmony_ci 725ffe3c632Sopenharmony_ci#pragma mark - Subset from from map_tests.cc 726ffe3c632Sopenharmony_ci 727ffe3c632Sopenharmony_ci// TEST(GeneratedMapFieldTest, CopyFromMessageMap) 728ffe3c632Sopenharmony_ci- (void)testMap_CopyFromMessageMap { 729ffe3c632Sopenharmony_ci TestMessageMap *msg1 = [[TestMessageMap alloc] init]; 730ffe3c632Sopenharmony_ci TestMessageMap *msg2 = [[TestMessageMap alloc] init]; 731ffe3c632Sopenharmony_ci 732ffe3c632Sopenharmony_ci TestAllTypes *subMsg = [TestAllTypes message]; 733ffe3c632Sopenharmony_ci subMsg.repeatedInt32Array = [GPBInt32Array arrayWithValue:100]; 734ffe3c632Sopenharmony_ci [msg1.mapInt32Message setObject:subMsg forKey:0]; 735ffe3c632Sopenharmony_ci subMsg = nil; 736ffe3c632Sopenharmony_ci 737ffe3c632Sopenharmony_ci subMsg = [TestAllTypes message]; 738ffe3c632Sopenharmony_ci subMsg.repeatedInt32Array = [GPBInt32Array arrayWithValue:101]; 739ffe3c632Sopenharmony_ci 740ffe3c632Sopenharmony_ci [msg2.mapInt32Message setObject:subMsg forKey:0]; 741ffe3c632Sopenharmony_ci subMsg = nil; 742ffe3c632Sopenharmony_ci 743ffe3c632Sopenharmony_ci [msg1 mergeFrom:msg2]; 744ffe3c632Sopenharmony_ci 745ffe3c632Sopenharmony_ci // Checks repeated field is overwritten. 746ffe3c632Sopenharmony_ci XCTAssertEqual(msg1.mapInt32Message.count, 1U); 747ffe3c632Sopenharmony_ci subMsg = [msg1.mapInt32Message objectForKey:0]; 748ffe3c632Sopenharmony_ci XCTAssertNotNil(subMsg); 749ffe3c632Sopenharmony_ci XCTAssertEqual(subMsg.repeatedInt32Array.count, 1U); 750ffe3c632Sopenharmony_ci XCTAssertEqual([subMsg.repeatedInt32Array valueAtIndex:0], 101); 751ffe3c632Sopenharmony_ci 752ffe3c632Sopenharmony_ci [msg2 release]; 753ffe3c632Sopenharmony_ci [msg1 release]; 754ffe3c632Sopenharmony_ci} 755ffe3c632Sopenharmony_ci 756ffe3c632Sopenharmony_ci@end 757