Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
85466206
Commit
85466206
authored
May 17, 2017
by
Thomas Van Lenten
Committed by
GitHub
May 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3104 from thomasvl/ext_registry_copy
Fix ExtensionRegistry copying and add tests.
parents
b28617b8
49e4ba60
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
187 additions
and
23 deletions
+187
-23
Makefile.am
Makefile.am
+1
-0
GPBExtensionRegistry.m
objectivec/GPBExtensionRegistry.m
+18
-19
project.pbxproj
objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
+6
-2
PerformanceTests.xcscheme
...codeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
+9
-0
project.pbxproj
objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
+6
-2
PerformanceTests.xcscheme
...codeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
+9
-0
GPBExtensionRegistryTest.m
objectivec/Tests/GPBExtensionRegistryTest.m
+138
-0
No files found.
Makefile.am
View file @
85466206
...
...
@@ -535,6 +535,7 @@ objectivec_EXTRA_DIST= \
objectivec/Tests/GPBDictionaryTests+UInt64.m
\
objectivec/Tests/GPBDictionaryTests.m
\
objectivec/Tests/GPBDictionaryTests.pddm
\
objectivec/Tests/GPBExtensionRegistryTest.m
\
objectivec/Tests/GPBMessageTests+Merge.m
\
objectivec/Tests/GPBMessageTests+Runtime.m
\
objectivec/Tests/GPBMessageTests+Serialization.m
\
...
...
objectivec/GPBExtensionRegistry.m
View file @
85466206
...
...
@@ -57,14 +57,16 @@
-
(
instancetype
)
copyWithZone
:
(
NSZone
*
)
zone
{
GPBExtensionRegistry
*
result
=
[[[
self
class
]
allocWithZone
:
zone
]
init
];
if
(
result
&&
mutableClassMap_
.
count
)
{
[
result
->
mutableClassMap_
addEntriesFromDictionary
:
mutableClassMap_
];
}
[
result
addExtensions
:
self
];
return
result
;
}
-
(
CFMutableDictionaryRef
)
extensionMapForContainingMessageClass
:
(
Class
)
containingMessageClass
{
-
(
void
)
addExtension
:
(
GPBExtensionDescriptor
*
)
extension
{
if
(
extension
==
nil
)
{
return
;
}
Class
containingMessageClass
=
extension
.
containingMessageClass
;
CFMutableDictionaryRef
extensionMap
=
(
CFMutableDictionaryRef
)
[
mutableClassMap_
objectForKey
:
containingMessageClass
];
if
(
extensionMap
==
nil
)
{
...
...
@@ -74,18 +76,9 @@
&
kCFTypeDictionaryValueCallBacks
);
[
mutableClassMap_
setObject
:(
id
)
extensionMap
forKey
:(
id
<
NSCopying
>
)
containingMessageClass
];
CFRelease
(
extensionMap
);
}
return
extensionMap
;
}
-
(
void
)
addExtension
:
(
GPBExtensionDescriptor
*
)
extension
{
if
(
extension
==
nil
)
{
return
;
}
Class
containingMessageClass
=
extension
.
containingMessageClass
;
CFMutableDictionaryRef
extensionMap
=
[
self
extensionMapForContainingMessageClass
:
containingMessageClass
];
ssize_t
key
=
extension
.
fieldNumber
;
CFDictionarySetValue
(
extensionMap
,
(
const
void
*
)
key
,
extension
);
}
...
...
@@ -119,10 +112,16 @@ static void CopyKeyValue(const void *key, const void *value, void *context) {
Class
containingMessageClass
=
key
;
CFMutableDictionaryRef
otherExtensionMap
=
(
CFMutableDictionaryRef
)
value
;
CFMutableDictionaryRef
extensionMap
=
[
self
extensionMapForContainingMessageClass
:
containingMessageClass
];
CFDictionaryApplyFunction
(
otherExtensionMap
,
CopyKeyValue
,
extensionMap
);
CFMutableDictionaryRef
extensionMap
=
(
CFMutableDictionaryRef
)
[
mutableClassMap_
objectForKey
:
containingMessageClass
];
if
(
extensionMap
==
nil
)
{
extensionMap
=
CFDictionaryCreateMutableCopy
(
kCFAllocatorDefault
,
0
,
otherExtensionMap
);
[
mutableClassMap_
setObject
:(
id
)
extensionMap
forKey
:(
id
<
NSCopying
>
)
containingMessageClass
];
CFRelease
(
extensionMap
);
}
else
{
CFDictionaryApplyFunction
(
otherExtensionMap
,
CopyKeyValue
,
extensionMap
);
}
}];
}
...
...
objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
View file @
85466206
...
...
@@ -52,6 +52,7 @@
F4487C751AADF7F500531423
/* GPBMessageTests+Runtime.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F4487C741AADF7F500531423
/* GPBMessageTests+Runtime.m */
;
};
F4487C7F1AAF62CD00531423
/* GPBMessageTests+Serialization.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F4487C7E1AAF62CD00531423
/* GPBMessageTests+Serialization.m */
;
};
F4487C831AAF6AB300531423
/* GPBMessageTests+Merge.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F4487C821AAF6AB300531423
/* GPBMessageTests+Merge.m */
;
};
F4584D821ECCB52A00803AB6
/* GPBExtensionRegistryTest.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F4584D7E1ECCB38900803AB6
/* GPBExtensionRegistryTest.m */
;
};
F45C69CC16DFD08D0081955B
/* GPBExtensionInternals.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F45C69CB16DFD08D0081955B
/* GPBExtensionInternals.m */
;
};
F45E57C71AE6DC6A000B7D99
/* text_format_map_unittest_data.txt in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F45E57C61AE6DC6A000B7D99
/* text_format_map_unittest_data.txt */
;
};
F47476E51D21A524007C7B1A
/* Duration.pbobjc.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
8B4248D41A92826400BC1EC6
/* Duration.pbobjc.m */
;
};
...
...
@@ -180,6 +181,7 @@
F4487C821AAF6AB300531423
/* GPBMessageTests+Merge.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"GPBMessageTests+Merge.m"
;
sourceTree
=
"<group>"
;
};
F44929001C866B1900C2548A
/* GPBCodedOutputStream_PackagePrivate.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
GPBCodedOutputStream_PackagePrivate.h
;
sourceTree
=
"<group>"
;
};
F451D3F51A8AAE8700B8A22C
/* GPBProtocolBuffers_RuntimeSupport.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
GPBProtocolBuffers_RuntimeSupport.h
;
sourceTree
=
"<group>"
;
};
F4584D7E1ECCB38900803AB6
/* GPBExtensionRegistryTest.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
GPBExtensionRegistryTest.m
;
sourceTree
=
"<group>"
;
};
F45C69CB16DFD08D0081955B
/* GPBExtensionInternals.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
GPBExtensionInternals.m
;
sourceTree
=
"<group>"
;
};
F45E57C61AE6DC6A000B7D99
/* text_format_map_unittest_data.txt */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
text
;
path
=
text_format_map_unittest_data.txt
;
sourceTree
=
"<group>"
;
};
F4AC9E1D1A8BEB3500BD6E83
/* unittest_cycle.proto */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text
;
path
=
unittest_cycle.proto
;
sourceTree
=
"<group>"
;
};
...
...
@@ -403,6 +405,7 @@
F4353D301AC06F10005A6198
/* GPBDictionaryTests+String.m */
,
F4353D311AC06F10005A6198
/* GPBDictionaryTests+UInt32.m */
,
F4353D321AC06F10005A6198
/* GPBDictionaryTests+UInt64.m */
,
F4584D7E1ECCB38900803AB6
/* GPBExtensionRegistryTest.m */
,
7461B6A30F94FDF800A0C422
/* GPBMessageTests.m */
,
F4487C821AAF6AB300531423
/* GPBMessageTests+Merge.m */
,
F4487C741AADF7F500531423
/* GPBMessageTests+Runtime.m */
,
...
...
@@ -418,8 +421,8 @@
7461B6BA0F94FDF900A0C422
/* GPBUtilitiesTests.m */
,
8B4248DB1A92933A00BC1EC6
/* GPBWellKnownTypesTest.m */
,
7461B6BC0F94FDF900A0C422
/* GPBWireFormatTests.m */
,
F43C88CF191D77FC009E917D
/* text_format_unittest_data.txt */
,
F45E57C61AE6DC6A000B7D99
/* text_format_map_unittest_data.txt */
,
F43C88CF191D77FC009E917D
/* text_format_unittest_data.txt */
,
8B7E6A7414893DBA00F8884A
/* unittest_custom_options.proto */
,
F4AC9E1D1A8BEB3500BD6E83
/* unittest_cycle.proto */
,
8B7E6A7514893DBA00F8884A
/* unittest_embed_optimize_for.proto */
,
...
...
@@ -429,8 +432,8 @@
8BBD9DB016DD1DC8008E1EC1
/* unittest_lite.proto */
,
8B7E6A7B14893DBC00F8884A
/* unittest_mset.proto */
,
8B7E6A7C14893DBC00F8884A
/* unittest_no_generic_services.proto */
,
8B09AAF614B663A7007B4184
/* unittest_objc.proto */
,
F4CF31701B162ED800BD9B06
/* unittest_objc_startup.proto */
,
8B09AAF614B663A7007B4184
/* unittest_objc.proto */
,
8B7E6A7D14893DBC00F8884A
/* unittest_optimize_for.proto */
,
F4487C781AADFB3100531423
/* unittest_runtime_proto2.proto */
,
F4487C791AADFB3200531423
/* unittest_runtime_proto3.proto */
,
...
...
@@ -669,6 +672,7 @@
F4F8D8831D789FD9002CE128
/* GPBUnittestProtos2.m in Sources */
,
F4353D1D1AB8822D005A6198
/* GPBDescriptorTests.m in Sources */
,
8B4248BB1A8C256A00BC1EC6
/* GPBSwiftTests.swift in Sources */
,
F4584D821ECCB52A00803AB6
/* GPBExtensionRegistryTest.m in Sources */
,
5102DABC1891A073002037B6
/* GPBConcurrencyTests.m in Sources */
,
F4487C751AADF7F500531423
/* GPBMessageTests+Runtime.m in Sources */
,
F4353D351AC06F10005A6198
/* GPBDictionaryTests+Int32.m in Sources */
,
...
...
objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
View file @
85466206
...
...
@@ -50,6 +50,12 @@
<Test
Identifier =
"DescriptorTests"
>
</Test>
<Test
Identifier =
"GPBAutocreatedArrayTests"
>
</Test>
<Test
Identifier =
"GPBAutocreatedDictionaryTests"
>
</Test>
<Test
Identifier =
"GPBBoolArrayTests"
>
</Test>
...
...
@@ -89,6 +95,9 @@
<Test
Identifier =
"GPBEnumArrayTests"
>
</Test>
<Test
Identifier =
"GPBExtensionRegistryTest"
>
</Test>
<Test
Identifier =
"GPBFloatArrayTests"
>
</Test>
...
...
objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
View file @
85466206
...
...
@@ -60,6 +60,7 @@
F4487C771AADF84900531423
/* GPBMessageTests+Runtime.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F4487C761AADF84900531423
/* GPBMessageTests+Runtime.m */
;
};
F4487C811AAF62FC00531423
/* GPBMessageTests+Serialization.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F4487C801AAF62FC00531423
/* GPBMessageTests+Serialization.m */
;
};
F4487C851AAF6AC500531423
/* GPBMessageTests+Merge.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F4487C841AAF6AC500531423
/* GPBMessageTests+Merge.m */
;
};
F4584D831ECCB53600803AB6
/* GPBExtensionRegistryTest.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F4584D801ECCB39E00803AB6
/* GPBExtensionRegistryTest.m */
;
};
F45C69CC16DFD08D0081955B
/* GPBExtensionInternals.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F45C69CB16DFD08D0081955B
/* GPBExtensionInternals.m */
;
};
F45E57C91AE6DC98000B7D99
/* text_format_map_unittest_data.txt in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
F45E57C81AE6DC98000B7D99
/* text_format_map_unittest_data.txt */
;
};
F47476E91D21A537007C7B1A
/* Duration.pbobjc.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
8B4248DE1A929C7D00BC1EC6
/* Duration.pbobjc.m */
;
};
...
...
@@ -202,6 +203,7 @@
F4487C841AAF6AC500531423
/* GPBMessageTests+Merge.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"GPBMessageTests+Merge.m"
;
sourceTree
=
"<group>"
;
};
F44929021C866B3B00C2548A
/* GPBCodedOutputStream_PackagePrivate.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
GPBCodedOutputStream_PackagePrivate.h
;
sourceTree
=
"<group>"
;
};
F451D3F61A8AAEA600B8A22C
/* GPBProtocolBuffers_RuntimeSupport.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
GPBProtocolBuffers_RuntimeSupport.h
;
sourceTree
=
"<group>"
;
};
F4584D801ECCB39E00803AB6
/* GPBExtensionRegistryTest.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
GPBExtensionRegistryTest.m
;
path
=
Tests/GPBExtensionRegistryTest.m
;
sourceTree
=
SOURCE_ROOT
;
};
F45C69CB16DFD08D0081955B
/* GPBExtensionInternals.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
GPBExtensionInternals.m
;
sourceTree
=
"<group>"
;
};
F45E57C81AE6DC98000B7D99
/* text_format_map_unittest_data.txt */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
text
;
path
=
text_format_map_unittest_data.txt
;
sourceTree
=
"<group>"
;
};
F4AC9E1C1A8BEB1000BD6E83
/* unittest_cycle.proto */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text
;
path
=
unittest_cycle.proto
;
sourceTree
=
"<group>"
;
};
...
...
@@ -441,6 +443,7 @@
F4353D3E1AC06F31005A6198
/* GPBDictionaryTests+String.m */
,
F4353D3F1AC06F31005A6198
/* GPBDictionaryTests+UInt32.m */
,
F4353D401AC06F31005A6198
/* GPBDictionaryTests+UInt64.m */
,
F4584D801ECCB39E00803AB6
/* GPBExtensionRegistryTest.m */
,
7461B6A30F94FDF800A0C422
/* GPBMessageTests.m */
,
F4487C841AAF6AC500531423
/* GPBMessageTests+Merge.m */
,
F4487C761AADF84900531423
/* GPBMessageTests+Runtime.m */
,
...
...
@@ -456,8 +459,8 @@
7461B6BA0F94FDF900A0C422
/* GPBUtilitiesTests.m */
,
8B4248E51A929C9900BC1EC6
/* GPBWellKnownTypesTest.m */
,
7461B6BC0F94FDF900A0C422
/* GPBWireFormatTests.m */
,
F43C88CF191D77FC009E917D
/* text_format_unittest_data.txt */
,
F45E57C81AE6DC98000B7D99
/* text_format_map_unittest_data.txt */
,
F43C88CF191D77FC009E917D
/* text_format_unittest_data.txt */
,
8B7E6A7414893DBA00F8884A
/* unittest_custom_options.proto */
,
F4AC9E1C1A8BEB1000BD6E83
/* unittest_cycle.proto */
,
8B7E6A7514893DBA00F8884A
/* unittest_embed_optimize_for.proto */
,
...
...
@@ -467,8 +470,8 @@
8BBD9DB016DD1DC8008E1EC1
/* unittest_lite.proto */
,
8B7E6A7B14893DBC00F8884A
/* unittest_mset.proto */
,
8B7E6A7C14893DBC00F8884A
/* unittest_no_generic_services.proto */
,
8B09AAF614B663A7007B4184
/* unittest_objc.proto */
,
F4CF31711B162EF500BD9B06
/* unittest_objc_startup.proto */
,
8B09AAF614B663A7007B4184
/* unittest_objc.proto */
,
8B7E6A7D14893DBC00F8884A
/* unittest_optimize_for.proto */
,
F4487C7A1AADFB5500531423
/* unittest_runtime_proto2.proto */
,
F4487C7B1AADFB5500531423
/* unittest_runtime_proto3.proto */
,
...
...
@@ -765,6 +768,7 @@
F4F8D8861D78A193002CE128
/* GPBUnittestProtos2.m in Sources */
,
F4B51B1C1BBC5C7100744318
/* GPBObjectiveCPlusPlusTest.mm in Sources */
,
8B4248B41A8BD96E00BC1EC6
/* GPBSwiftTests.swift in Sources */
,
F4584D831ECCB53600803AB6
/* GPBExtensionRegistryTest.m in Sources */
,
5102DABC1891A073002037B6
/* GPBConcurrencyTests.m in Sources */
,
F4487C771AADF84900531423
/* GPBMessageTests+Runtime.m in Sources */
,
F4353D431AC06F31005A6198
/* GPBDictionaryTests+Int32.m in Sources */
,
...
...
objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
View file @
85466206
...
...
@@ -50,6 +50,12 @@
<Test
Identifier =
"DescriptorTests"
>
</Test>
<Test
Identifier =
"GPBAutocreatedArrayTests"
>
</Test>
<Test
Identifier =
"GPBAutocreatedDictionaryTests"
>
</Test>
<Test
Identifier =
"GPBBoolArrayTests"
>
</Test>
...
...
@@ -89,6 +95,9 @@
<Test
Identifier =
"GPBEnumArrayTests"
>
</Test>
<Test
Identifier =
"GPBExtensionRegistryTest"
>
</Test>
<Test
Identifier =
"GPBFloatArrayTests"
>
</Test>
...
...
objectivec/Tests/GPBExtensionRegistryTest.m
0 → 100644
View file @
85466206
// Protocol Buffers - Google's data interchange format
// Copyright 2017 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import "GPBTestUtilities.h"
#import "GPBExtensionRegistry.h"
#import "google/protobuf/Unittest.pbobjc.h"
@interface
GPBExtensionRegistryTest
:
GPBTestCase
@end
@implementation
GPBExtensionRegistryTest
-
(
void
)
testBasics
{
GPBExtensionRegistry
*
reg
=
[[[
GPBExtensionRegistry
alloc
]
init
]
autorelease
];
XCTAssertNotNil
(
reg
);
XCTAssertNil
([
reg
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
1
]);
XCTAssertNil
([
reg
extensionForDescriptor
:[
TestAllTypes
descriptor
]
fieldNumber
:
1
]);
[
reg
addExtension
:[
UnittestRoot
optionalInt32Extension
]];
[
reg
addExtension
:[
UnittestRoot
packedInt64Extension
]];
XCTAssertTrue
([
reg
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
1
]
==
[
UnittestRoot
optionalInt32Extension
]);
// ptr equality
XCTAssertNil
([
reg
extensionForDescriptor
:[
TestAllTypes
descriptor
]
fieldNumber
:
1
]);
XCTAssertTrue
([
reg
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
91
]
==
[
UnittestRoot
packedInt64Extension
]);
// ptr equality
}
-
(
void
)
testCopy
{
GPBExtensionRegistry
*
reg1
=
[[[
GPBExtensionRegistry
alloc
]
init
]
autorelease
];
[
reg1
addExtension
:[
UnittestRoot
optionalInt32Extension
]];
GPBExtensionRegistry
*
reg2
=
[[
reg1
copy
]
autorelease
];
XCTAssertNotNil
(
reg2
);
XCTAssertTrue
([
reg1
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
1
]
==
[
UnittestRoot
optionalInt32Extension
]);
// ptr equality
XCTAssertTrue
([
reg2
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
1
]
==
[
UnittestRoot
optionalInt32Extension
]);
// ptr equality
// Message class that had registered extension(s) at the -copy time.
[
reg1
addExtension
:[
UnittestRoot
optionalBoolExtension
]];
[
reg2
addExtension
:[
UnittestRoot
optionalStringExtension
]];
XCTAssertTrue
([
reg1
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
13
]
==
[
UnittestRoot
optionalBoolExtension
]);
// ptr equality
XCTAssertNil
([
reg1
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
14
]);
XCTAssertNil
([
reg2
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
13
]);
XCTAssertTrue
([
reg2
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
14
]
==
[
UnittestRoot
optionalStringExtension
]);
// ptr equality
// Message class that did not have any registered extensions at the -copy time.
[
reg1
addExtension
:[
UnittestRoot
packedInt64Extension
]];
[
reg2
addExtension
:[
UnittestRoot
packedSint32Extension
]];
XCTAssertTrue
([
reg1
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
91
]
==
[
UnittestRoot
packedInt64Extension
]);
// ptr equality
XCTAssertNil
([
reg1
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
94
]);
XCTAssertNil
([
reg2
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
91
]);
XCTAssertTrue
([
reg2
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
94
]
==
[
UnittestRoot
packedSint32Extension
]);
// ptr equality
}
-
(
void
)
testAddExtensions
{
GPBExtensionRegistry
*
reg1
=
[[[
GPBExtensionRegistry
alloc
]
init
]
autorelease
];
[
reg1
addExtension
:[
UnittestRoot
optionalInt32Extension
]];
GPBExtensionRegistry
*
reg2
=
[[[
GPBExtensionRegistry
alloc
]
init
]
autorelease
];
XCTAssertNil
([
reg2
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
1
]);
[
reg2
addExtensions
:
reg1
];
XCTAssertTrue
([
reg2
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
1
]
==
[
UnittestRoot
optionalInt32Extension
]);
// ptr equality
// Confirm adding to the first doesn't add to the second.
[
reg1
addExtension
:[
UnittestRoot
optionalBoolExtension
]];
[
reg1
addExtension
:[
UnittestRoot
packedInt64Extension
]];
XCTAssertTrue
([
reg1
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
13
]
==
[
UnittestRoot
optionalBoolExtension
]);
// ptr equality
XCTAssertTrue
([
reg1
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
91
]
==
[
UnittestRoot
packedInt64Extension
]);
// ptr equality
XCTAssertNil
([
reg2
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
13
]);
XCTAssertNil
([
reg2
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
91
]);
// Confirm adding to the second doesn't add to the first.
[
reg2
addExtension
:[
UnittestRoot
optionalStringExtension
]];
[
reg2
addExtension
:[
UnittestRoot
packedSint32Extension
]];
XCTAssertNil
([
reg1
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
14
]);
XCTAssertNil
([
reg1
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
94
]);
XCTAssertTrue
([
reg2
extensionForDescriptor
:[
TestAllExtensions
descriptor
]
fieldNumber
:
14
]
==
[
UnittestRoot
optionalStringExtension
]);
// ptr equality
XCTAssertTrue
([
reg2
extensionForDescriptor
:[
TestPackedExtensions
descriptor
]
fieldNumber
:
94
]
==
[
UnittestRoot
packedSint32Extension
]);
// ptr equality
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment