@@ -66,14 +66,17 @@ public virtual void Before() {
66
66
67
67
[ NUnit . Framework . Test ]
68
68
public virtual void ValidObjectsTest ( ) {
69
+ int maxNameLength = pdfA1Checker . GetMaxNameLength ( ) ;
69
70
int maxStringLength = pdfA1Checker . GetMaxStringLength ( ) ;
70
71
int maxArrayCapacity = MAX_ARRAY_CAPACITY ;
71
72
int maxDictionaryCapacity = MAX_DICTIONARY_CAPACITY ;
72
73
long maxIntegerValue = pdfA1Checker . GetMaxIntegerValue ( ) ;
73
74
long minIntegerValue = pdfA1Checker . GetMinIntegerValue ( ) ;
74
75
double maxRealValue = pdfA1Checker . GetMaxRealValue ( ) ;
75
76
NUnit . Framework . Assert . AreEqual ( 65535 , maxStringLength ) ;
77
+ NUnit . Framework . Assert . AreEqual ( 127 , maxNameLength ) ;
76
78
PdfString longString = PdfACheckerTestUtils . GetLongString ( maxStringLength ) ;
79
+ PdfName longName = PdfACheckerTestUtils . GetLongName ( maxNameLength ) ;
77
80
PdfArray longArray = PdfACheckerTestUtils . GetLongArray ( maxArrayCapacity ) ;
78
81
PdfDictionary longDictionary = PdfACheckerTestUtils . GetLongDictionary ( maxDictionaryCapacity ) ;
79
82
NUnit . Framework . Assert . AreEqual ( 2147483647 , maxIntegerValue ) ;
@@ -82,8 +85,8 @@ public virtual void ValidObjectsTest() {
82
85
PdfNumber largeInteger = new PdfNumber ( maxIntegerValue ) ;
83
86
PdfNumber negativeInteger = new PdfNumber ( minIntegerValue ) ;
84
87
PdfNumber largeReal = new PdfNumber ( maxRealValue - 0.001 ) ;
85
- PdfObject [ ] largeObjects = new PdfObject [ ] { longString , longArray , longDictionary , largeInteger , negativeInteger
86
- , largeReal } ;
88
+ PdfObject [ ] largeObjects = new PdfObject [ ] { longName , longString , longArray , longDictionary , largeInteger
89
+ , negativeInteger , largeReal } ;
87
90
// No exceptions should not be thrown as all values match the
88
91
// limitations provided in specification
89
92
foreach ( PdfObject largeObject in largeObjects ) {
@@ -120,6 +123,18 @@ public virtual void IndependentLongStringTest() {
120
123
;
121
124
}
122
125
126
+ [ NUnit . Framework . Test ]
127
+ public virtual void IndependentLongNameTest ( ) {
128
+ NUnit . Framework . Assert . That ( ( ) => {
129
+ PdfName longName = BuildLongName ( ) ;
130
+ // An exception should be thrown as provided name is longer then
131
+ // it is allowed per specification
132
+ pdfA1Checker . CheckPdfObject ( longName ) ;
133
+ }
134
+ , NUnit . Framework . Throws . InstanceOf < PdfAConformanceException > ( ) . With . Message . EqualTo ( PdfAConformanceException . PDF_NAME_IS_TOO_LONG ) )
135
+ ;
136
+ }
137
+
123
138
[ NUnit . Framework . Test ]
124
139
public virtual void IndependentLargeIntegerTest ( ) {
125
140
NUnit . Framework . Assert . That ( ( ) => {
@@ -200,6 +215,22 @@ public virtual void LongStringInDictionaryTest() {
200
215
;
201
216
}
202
217
218
+ [ NUnit . Framework . Test ]
219
+ public virtual void LongNameAsKeyInDictionaryTest ( ) {
220
+ NUnit . Framework . Assert . That ( ( ) => {
221
+ PdfName longName = BuildLongName ( ) ;
222
+ PdfDictionary dict = new PdfDictionary ( ) ;
223
+ dict . Put ( new PdfName ( "Key1" ) , new PdfString ( "value1" ) ) ;
224
+ dict . Put ( new PdfName ( "Key2" ) , new PdfString ( "value2" ) ) ;
225
+ dict . Put ( longName , new PdfString ( "value3" ) ) ;
226
+ // An exception should be thrown as dictionary contains key which is longer then
227
+ // it is allowed per specification
228
+ pdfA1Checker . CheckPdfObject ( dict ) ;
229
+ }
230
+ , NUnit . Framework . Throws . InstanceOf < PdfAConformanceException > ( ) . With . Message . EqualTo ( PdfAConformanceException . PDF_NAME_IS_TOO_LONG ) )
231
+ ;
232
+ }
233
+
203
234
[ NUnit . Framework . Test ]
204
235
public virtual void LongStringInArrayTest ( ) {
205
236
NUnit . Framework . Assert . That ( ( ) => {
@@ -224,6 +255,18 @@ public virtual void LongStringInContentStreamTest() {
224
255
;
225
256
}
226
257
258
+ [ NUnit . Framework . Test ]
259
+ public virtual void LongNameInContentStreamTest ( ) {
260
+ NUnit . Framework . Assert . That ( ( ) => {
261
+ PdfName longName = BuildLongName ( ) ;
262
+ // An exception should be thrown as content stream has a name which
263
+ // is longer then it is allowed per specification
264
+ CheckInContentStream ( longName ) ;
265
+ }
266
+ , NUnit . Framework . Throws . InstanceOf < PdfAConformanceException > ( ) . With . Message . EqualTo ( PdfAConformanceException . PDF_NAME_IS_TOO_LONG ) )
267
+ ;
268
+ }
269
+
227
270
[ NUnit . Framework . Test ]
228
271
public virtual void LargeIntegerInContentStreamTest ( ) {
229
272
NUnit . Framework . Assert . That ( ( ) => {
@@ -327,6 +370,22 @@ public virtual void LongStringInDictionaryInContentStreamTest() {
327
370
;
328
371
}
329
372
373
+ [ NUnit . Framework . Test ]
374
+ public virtual void LongNameAsKeyInDictionaryInContentStreamTest ( ) {
375
+ NUnit . Framework . Assert . That ( ( ) => {
376
+ PdfName longName = BuildLongName ( ) ;
377
+ PdfDictionary dict = new PdfDictionary ( ) ;
378
+ dict . Put ( new PdfName ( "Key1" ) , new PdfString ( "value1" ) ) ;
379
+ dict . Put ( new PdfName ( "Key2" ) , new PdfString ( "value2" ) ) ;
380
+ dict . Put ( longName , new PdfString ( "value3" ) ) ;
381
+ // An exception should be thrown as content stream has a string which
382
+ // is longer then it is allowed per specification
383
+ CheckInContentStream ( dict ) ;
384
+ }
385
+ , NUnit . Framework . Throws . InstanceOf < PdfAConformanceException > ( ) . With . Message . EqualTo ( PdfAConformanceException . PDF_NAME_IS_TOO_LONG ) )
386
+ ;
387
+ }
388
+
330
389
[ NUnit . Framework . Test ]
331
390
public virtual void LongStringInComplexStructureTest ( ) {
332
391
NUnit . Framework . Assert . That ( ( ) => {
@@ -433,6 +492,13 @@ private PdfString BuildLongString() {
433
492
return PdfACheckerTestUtils . GetLongString ( testLength ) ;
434
493
}
435
494
495
+ private PdfName BuildLongName ( ) {
496
+ int maxAllowedLength = pdfA1Checker . GetMaxNameLength ( ) ;
497
+ int testLength = maxAllowedLength + 1 ;
498
+ NUnit . Framework . Assert . AreEqual ( 128 , testLength ) ;
499
+ return PdfACheckerTestUtils . GetLongName ( testLength ) ;
500
+ }
501
+
436
502
private PdfArray BuildLongArray ( ) {
437
503
int testLength = MAX_ARRAY_CAPACITY + 1 ;
438
504
return PdfACheckerTestUtils . GetLongArray ( testLength ) ;
0 commit comments