summaryrefslogblamecommitdiffstats
path: root/private/oleutest/cfmex/ctest.cxx
blob: e2de08c3c504848f3e61303b4b3d6e59c996b0db (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283


































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                


//+=======================================================================
//
//  File:       CTest.cxx
//
//  Purpose:    Define the CTest class.
//
//              This class is the test engine for the CreateFileMonikerEx
//              (CFMEx) DRTs.  All interactions with monikers are handled
//              through the CMoniker class.
//
//+=======================================================================


//  -------------
//  Include Files
//  -------------

#define _DCOM_			// Allow DCOM extensions (e.g., CoInitializeEx).

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <wtypes.h>
#include <oaidl.h>
#include <dsys.h>
#include <olecairo.h>
#include "CDir.hxx"
#include "CMoniker.hxx"
#include "CTest.hxx"


//+------------------------------------------------------------------------
//
//  Function:   CTest::CTest
//
//  Synopsis:   Inititialize member variables.
//
//  Inputs:     None.
//
//  Outputs:    N/A
//
//  Effects:    All members are initialized/defaulted.
//
//+------------------------------------------------------------------------


CTest::CTest( )
{

    m_lError = 0L;
    *m_wszErrorMessage = L'\0';

    m_pcDirectoryOriginal = NULL;
    m_pcDirectoryFinal = NULL;

}   // CTest::CTest

//+------------------------------------------------------------------------------
//
//  Function:   CTest::~CTest
//
//  Synopsis:   No action.
//
//  Inputs:     N/A
//
//  Outputs:    N/A
//
//  Effects:    None.
//
//+------------------------------------------------------------------------------


CTest::~CTest()
{
}   // CTest::~CTest


//+-------------------------------------------------------------------------------
//
//  Function:   CTest::Initialize
//
//  Synopsis:   Inititialize a CTest object.
//
//  Inputs:     CDirectory objects representing the original and final
//              locations of a link source file.  The original location
//              is used in CreateTemporaryStorage(), and the final location
//              is used in RenameTemporaryStorage().
//
//  Outputs:    TRUE if successful, FALSE otherwise.
//
//  Effects:    m_cDirectoryOriginal and m_cDirectoryFinal are set.
//
//+-------------------------------------------------------------------------------


BOOL CTest::Initialize( const CDirectory& cDirectoryOriginal,
                        const CDirectory& cDirectoryFinal
                      )
{
    //  -----
    //  Begin
    //  -----

    m_pcDirectoryOriginal = &cDirectoryOriginal;
    m_pcDirectoryFinal    = &cDirectoryFinal;

    m_cMoniker.Initialize( cDirectoryOriginal, cDirectoryFinal );

    //  ----
    //  Exit
    //  ----

    return TRUE;

}   // CTest::Initialize

//+-------------------------------------------------------------------------
//
//  Function:   CTest::CreateFileMonikerEx
//
//  Synopsis:   Verify that CreateFileMonikerEx actually creates a
//              *tracking* file moniker.  This is done by creating
//              the file moniker, renaming the link source,
//              Reducing the moniker, and getting the display name
//              of the reduced moniker.  Note that this tests
//              both CreateFileMonikerEx and Reduce.
//
//  Inputs:     None.
//
//  Outputs:    TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+-------------------------------------------------------------------------


BOOL CTest::CreateFileMonikerEx( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    WCHAR wszDisplayName[ MAX_PATH + sizeof( L'\0' ) ];
    IMoniker* pmnkReduced = NULL;

    //  -----
    //  Begin
    //  -----

    wprintf( L"CreateFileMonikerEx()\n" );
    wprintf( L"   Create a tracking file moniker (using CreateFileMonikerEx),\n"
             L"   move the represented file, Reduce the moniker, and get\n"
	     L"   the display name from the reduced moniker.  It should be the\n"
	     L"   new file name.  This test covers both CreateFileMonikerEx and\n"
             L"   Reduce.\n" );


    // Create the tracking file moniker.

    if( !m_cMoniker.CreateFileMonikerEx( ) )
        EXIT( L"Could not CreateFileMonikerEx" );

    // Rename the link source file.

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    // Reduce the tracking file moniker

    if( !m_cMoniker.Reduce( INFINITE, &pmnkReduced ))
	EXIT( L"Could not reduce the moniker" );

    // Use the reduced (non-tracking) file moniker to get the display name.

    if( !m_cMoniker.GetDisplayName( wszDisplayName, pmnkReduced ))
        EXIT( L"Could not get the display name" );

    // Validate the display name.

    if( _wcsicmp( wszDisplayName, m_cMoniker.GetTemporaryStorageName() ))
        EXIT( L"Failed" );
    

    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    m_cMoniker.DeleteTemporaryStorage();

    DisplayErrors( bSuccess, L"CTest::CreateFileMonikerEx()" );
    return( bSuccess );

}   // CTest::CreateFileMonikerEx()


//+--------------------------------------------------------------------------
//
//  Function:   CTest::GetDisplayName
//
//  Synopsis:   Create a tracking file moniker, get its display name,
//              rename the link source file, and get the display name again.
//              The value of the second display name will depend on whether
//              or not the original and final link source are within the set
//              of local indexed volumes.
//
//  Inputs:     None.
//
//  Outputs:    TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+--------------------------------------------------------------------------


BOOL CTest::GetDisplayName( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    WCHAR wszFinalDisplayName[ MAX_PATH + sizeof( L'\0' ) ];
    WCHAR wszOriginalDisplayName[ MAX_PATH + sizeof( L'\0' ) ];

    //  -----
    //  Begin
    //  -----

    wprintf( L"GetDisplayName()\n" );
    wprintf( L"   Create a tracking file moniker, move the represented file,\n"
             L"   and perform a GetDisplayName on the moniker.  If the original\n"
             L"   and final locations of the source file are within the set of local\n"
             L"   indexed drives, the display name will represent the final file name.\n"
             L"   Otherwise, it will represent the original display name.\n" );

    // Create a tracking file moniker.

    if( !m_cMoniker.CreateFileMonikerEx(  ) )
        EXIT( L"Could not CreateFileMonikerEx" );

    // Get its display name.

    if( !m_cMoniker.GetDisplayName( wszOriginalDisplayName ))
        EXIT( L"Could not get the original display name" );

    // Rename the link source.

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    // Get the renamed moniker's display name.

    if( !m_cMoniker.GetDisplayName( wszFinalDisplayName ))
        EXIT( L"Could not get the final display name" );

    // Was and is the link source on a local, indexed volume?

    if( ( m_pcDirectoryOriginal->GetFileSystemType() == fstOFS )
        &&
        ( m_pcDirectoryOriginal->GetFileSystemType() == fstOFS )
      )
    {
        // Yes, so the GetDisplayName should have tracked the rename.

        if( _wcsicmp( wszFinalDisplayName, m_cMoniker.GetTemporaryStorageName() ))
            EXIT( L"Failed" );
    }
    else
    {
        // No, so the GetDisplayName should have returned the original name.

        if( _wcsicmp( wszOriginalDisplayName, wszFinalDisplayName ))
            EXIT( L"Failed" );
    }

    
    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    m_cMoniker.DeleteTemporaryStorage();

    DisplayErrors( bSuccess, L"CTest::GetDisplayName()" );
    return( bSuccess );

}   // CTest::GetDisplayName()



//+--------------------------------------------------------------------------
//
//  Function:   CTest::GetTimeOfLastChange
//
//  Synopsis:   Create a tracking file moniker, rename it, sleep, and
//              touch it.  If the original and final link sources are
//              on local, indexed volumes, then a GetDisplayName should
//              return the final link source's time.  Otherwise, it should
//              return the original link source's time.
//
//  Inputs:     None.
//
//  Outputs:    TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+--------------------------------------------------------------------------


BOOL CTest::GetTimeOfLastChange( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    FILETIME ftOriginal;
    FILETIME ftFinal;
    FILETIME ftMoniker;

    //  -----
    //  Begin
    //  -----

    wprintf( L"GetTimeOfLastChange()\n" );
    wprintf( L"   Create a tracking file moniker and move it.  Then touch (set the Access\n"
             L"   time) on the link source, and perform a GetTimeOfLastChange on the Moniker.\n"
             L"   If the original and final location of the link source is within the set\n"
             L"   of local indexed volumes, then the time returned from the moniker should\n"
             L"   match that of the post-touch link source.  Otherwise it should match the\n"
             L"   link sources original time.\n" );

    // Create a tracking file moniker.

    if( !m_cMoniker.CreateFileMonikerEx( TRACK_LOCALONLY ) )
        EXIT( L"Could not CreateFileMonikerEx" );

    // Get the link source's current time.

    if( !m_cMoniker.GetTemporaryStorageTime( &ftOriginal ))
        EXIT( L"Could not get original file time" );

    // Move the link source.

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    // Delay so that when we touch the final link source, its time
    // will be noticably different from the original link source's time.

    {
        wprintf( L"   Sleeping to let the time change:  " );
        for( int i = 0; i < 10; i++ )   // Sleep for 5 seconds
        {
            wprintf( L"z" );
            Sleep( 500 );   // 1/2 second
        }
        wprintf( L"\n" );
    }

    // Touch the final link source.

    if( !m_cMoniker.TouchTemporaryStorage())
        EXIT( L"Could not touch temporary storage" );

    // Get the final link source's time from the file system.

    if( !m_cMoniker.GetTemporaryStorageTime( &ftFinal ))
        EXIT( L"could not get final file time" );

    // Get the final link source's time from the moniker.

    if( !m_cMoniker.GetTimeOfLastChange( &ftMoniker ))
        EXIT( L"Could not get the time of last change" );

    // Is the original & final location of the link source file
    // in the set of local, indexed volumes?

    if( ( m_pcDirectoryOriginal->GetFileSystemType() == fstOFS )
        &&
        ( m_pcDirectoryOriginal->GetFileSystemType() == fstOFS )
      )
    {
        // Yes.  GetTimeOfLastChange should therefore have found
        // the time of the final link source file.

        if( memcmp( &ftFinal, &ftMoniker, sizeof( FILETIME ) ))
            EXIT( L"Failed" );
    }
    else
    {
        // No.  GetTimeOfLastChange should therefore have returned
        // the time of the original link source file.

        if( memcmp( &ftOriginal, &ftMoniker, sizeof( FILETIME ) ))
            EXIT( L"Failed" );
    }


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    m_cMoniker.DeleteTemporaryStorage();

    DisplayErrors( bSuccess, L"CTest::GetTimeOfLastChange()" );
    return( bSuccess );

}   // CTest::GetTimeOfLastChange()


//+--------------------------------------------------------------------
//
//  Function:   CTest::BindToObject
//
//  Synopsis:   Create a tracking file moniker, move the link source,
//              and attempt to bind to it with a BindToObject.
//              Since presumably the temporary file we're using as a link
//              source has no server, this will fail.  But any failure
//              downstream of locating the link source file will be
//              ignored.
//
//  Inputs:     None.
//
//  Output:     TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+--------------------------------------------------------------------


BOOL CTest::BindToObject( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    //  -----
    //  Begin
    //  -----

    wprintf( L"BindToObject()\n" );
    wprintf( L"   Create a tracking file moniker, moved the represented file,\n"
             L"   and attempt a BindToStorage() (which should succeed).\n" );

    // Create a tracking file moniker.

    if( !m_cMoniker.CreateFileMonikerEx( ) )
        EXIT( L"Could not CreateFileMonikerEx" );

    // Move the link source file.

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    // Attempt a bind.

    if( !m_cMoniker.BindToObject( ))
        EXIT( L"Could not bind to Object" );


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----
Exit:

    m_cMoniker.DeleteTemporaryStorage();

    DisplayErrors( bSuccess, L"CTest::BindToObject()" );
    return( bSuccess );

}   // CTest::BindToObject()


//+-----------------------------------------------------------
//
//  Function:   CTest::IPersist
//
//  Synopsis:   Create a tracking file moniker, move the link
//              source, and perform the CMoniker::SaveDeleteLoad
//              test.
//
//  Inputs:     None.
//
//  Output:     TRUE if successful, FALSE otherwise
//
//  Effects:    None.
//
//+-----------------------------------------------------------


BOOL CTest::IPersist( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    //  -----
    //  Begin
    //  -----

    wprintf( L"IPersist()\n" );
    wprintf( L"  Create a tracking file moniker (using CreateFileMonikerEx), and\n"
             L"  save it to a Stream.  Delete the moniker, create a new one using\n"
             L"  CreateFileMoniker, load it from the Stream, and verify that the resulting\n"
             L"  file moniker is tracking.\n" );

    // Create a tracking file moniker.

    if( !m_cMoniker.CreateFileMonikerEx( ) )
        EXIT( L"Could not CreateFileMonikerEx" );

    // Rename the link source.

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    // Save the moniker, deleted, create a new moniker, and reload it.

    if( !m_cMoniker.SaveDeleteLoad( ))
        EXIT( L"Failed SaveDeleteLoad" );


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    m_cMoniker.DeleteTemporaryStorage();

    DisplayErrors( bSuccess, L"CTest::IPersist()" );
    return( bSuccess );

}   // CTest::IPersist()


//+----------------------------------------------------------------------
//
//  Function:   CTest::ComposeWith
//
//  Synopsis:   Create a tracking file moniker, and use it in the 
//              CMoniker::ComposeWith operation.
//
//  Inputs:     None.
//
//  Output:     TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+----------------------------------------------------------------------

BOOL CTest::ComposeWith( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    IMoniker* pmnkReduced = NULL;
    WCHAR wszDisplayName[ MAX_PATH + sizeof( L'\0' )];

    //  -----
    //  Begin
    //  -----

    m_lError = 0;

    wprintf( L"ComposeWith()\n" );
    wprintf( L"   Create a tracking file moniker, and compose it with a non-tracking\n"
             L"   file moniker on the right.  The resulting moniker should be tracking.\n" );

    // Create the tracking file moniker.

    if( !m_cMoniker.CreateFileMonikerEx( ) )
        EXIT( L"Could not CreateFileMonikerEx" );

    // Perform the ComposeWith operation.

    if( !m_cMoniker.ComposeWith( ))
        EXIT( L"Failed ComposeWith" );

    // Move the link source file.

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    // Reduce the composed moniker.

    if( !m_cMoniker.Reduce( INFINITE, &pmnkReduced ))
	EXIT( L"Could not reduce the moniker" );

    // Get the display name on the reduced moniker.

    if( !m_cMoniker.GetDisplayName( wszDisplayName, pmnkReduced ))
        EXIT( L"Could not get the display name" );

    // Verify that the name from the moniker is the actual link source
    // file's new name.

    if( _wcsicmp( wszDisplayName, m_cMoniker.GetTemporaryStorageName() ))
        EXIT( L"Failed" );

    
    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    m_cMoniker.DeleteTemporaryStorage();

    DisplayErrors( bSuccess, L"CTest::ComposeWith()" );
    return( bSuccess );

}   // CTest::ComposeWith()


//+------------------------------------------------------------------
//
//  Function:   CTest::BindToStorage
//
//  Synopsis:   Create a tracking file moniker, and perform the
//              CMoniker::BindToStorage operation.
//
//  Inputs:     None.
//
//  Output:     TRUE if successful, FALSE otherwise.
//
//+------------------------------------------------------------------


BOOL CTest::BindToStorage( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    //  -----
    //  Begin
    //  -----

    m_lError = 0;

    wprintf( L"BindToStorage()\n" );
    wprintf( L"   Create a tracking file moniker (using CreateFileMonikerEx),\n"
             L"   move the represented file, Reduce the moniker, and get\n"
	     L"   the display name from the reduced moniker.  It should be the\n"
	     L"   new file name.  This test covers both CreateFileMonikerEx and\n"
             L"   Reduce.\n" );

    // Create the tracking file moniker.

    if( !m_cMoniker.CreateFileMonikerEx( ) )
        EXIT( L"Could not CreateFileMonikerEx" );

    // Move the link source file.

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    // Bind to the Storage

    if( !m_cMoniker.BindToStorage( ))
        EXIT( L"Could not bind to Storage" );


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    m_cMoniker.DeleteTemporaryStorage();

    DisplayErrors( bSuccess, L"CTest::BindToStorage()" );
    return( bSuccess );

}   // CTest::BindToStorage()


//+--------------------------------------------------------------------------
//
//  Function:   CTest::DeleteLinkSource
//
//  Synopsis:   Create a tracking file moniker, delete the link source,
//              and attempt a Reduce.  The Reduce should not fail, but
//              it should return an HResult of MK_S_REDUCED_TO_SELF.
//
//  Inputs:     Tick count limit on the length of the Reduce operation.
//
//  Output:     TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+--------------------------------------------------------------------------

BOOL CTest::DeleteLinkSource( DWORD dwDelay )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    WCHAR wszTimeout[ 80 ];

    //  -----
    //  Begin
    //  -----

    m_lError = 0L;

    // Generate a string which shows what the delay is.

    switch( dwDelay )
    {
        case 0:
            wcscpy( wszTimeout, L"instant timeout" );
            break;

        case INFINITE:
            wcscpy( wszTimeout, L"infinite timeout" );
            break;

        default:
            wsprintf( wszTimeout, L"%d ms timeout", dwDelay );
    }

    // Display a header.

    wprintf( L"Delete Link Source (%s)\n",
             wszTimeout );
    wprintf( L"   Create a tracking file moniker, then delete the link source, and\n"
             L"   attempt a reduce with a %s.\n",
             wszTimeout );

    // Create a tracking file moniker.

    if( !m_cMoniker.CreateFileMonikerEx( ) )
        EXIT( L"Could not CreateFileMonikerEx" );

    // Delete the link source file.

    if( !m_cMoniker.DeleteTemporaryStorage() )
        EXIT( L"Could not delete temporary storage" );

    // Tell CMoniker not to alarm the user with error messages.

    m_cMoniker.SuppressErrorMessages( TRUE );

    // Reduce the moniker, and verify it returns the proper Success code.

    if( !m_cMoniker.Reduce( dwDelay )
        ||
        m_cMoniker.GetHResult() != MK_S_REDUCED_TO_SELF
      )
	EXIT( L"Failed" );


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    m_cMoniker.DeleteTemporaryStorage();
    m_cMoniker.SuppressErrorMessages( FALSE );

    DisplayErrors( bSuccess, L"CTest::DeleteLinkSource()" );
    return( bSuccess );

}   // CTest::DeleteLinkSource()


//+------------------------------------------------------------------
//
//  Function:   CTest::GetOversizedBindOpts
//
//  Synopsis:   Test a bind context's ability to return a BIND_OPTS
//              which is larger than expected.
//
//              First, initialize the default BIND_OPTS in the bind
//              context to 1s.  Then, ask for a large BIND_OPTS.
//              The resulting buffer should have 1s up to the size of
//              the normal BIND_OPTS, and 0s for the remainder of the
//              buffer.  The length, however, should be that of the large
//              buffer.
//
//  Inputs:     None.
//
//  Outputs:    TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+------------------------------------------------------------------


BOOL CTest::GetOversizedBindOpts( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    BIND_OPTS   bind_opts;
    LPBIND_OPTS pbind_optsLarge    = (LPBIND_OPTS) new BYTE[ SIZE_OF_LARGE_BIND_OPTS ];
    LPBIND_OPTS pbind_optsExpected = (LPBIND_OPTS) new BYTE[ SIZE_OF_LARGE_BIND_OPTS ];

    //  -----
    //  Begin
    //  -----

    m_lError = 0L;

    wprintf( L"Get Oversized BindOpts\n" );
    wprintf( L"   Create a buffer which is much larger than a normal BIND_OPTS, and\n"
             L"   use it to request the BIND_OPTS from a bind context.  The length\n"
             L"   of the resulting buffer should be the large value, and the extra\n"
             L"   room in the buffer should be all 0s.\n" );


    // Validate our 'new' operations.

    if( pbind_optsLarge == NULL )
        EXIT( L"Could not allocate pbind_optsLarge" );
    pbind_optsLarge->cbStruct = SIZE_OF_LARGE_BIND_OPTS;

    if( pbind_optsExpected == NULL )
        EXIT( L"Could not allocate pbind_optsExpected" );
    pbind_optsExpected->cbStruct = SIZE_OF_LARGE_BIND_OPTS;


    // Initialize the bind_opts (normal sized) in the bind context to 1s.

    if( !m_cMoniker.InitializeBindContext() )
        EXIT( L"Could not initialize the bind context" );

    memset( &bind_opts, 1, sizeof( bind_opts ));
    bind_opts.cbStruct = sizeof( bind_opts );;

    m_lError = m_cMoniker.GetBindCtx()->SetBindOptions( &bind_opts );
    if( FAILED( m_lError )) EXIT( L"Could not set original bind options" );

    // Initialize the large bind_opts to 2s, then retrieve the bind_opts into
    // this structure.  This is done to verify that the GetBindOptions below
    // fills in the entire requested buffer (overwirting all of the 2s).

    memset( pbind_optsLarge, 2, SIZE_OF_LARGE_BIND_OPTS );
    pbind_optsLarge->cbStruct = SIZE_OF_LARGE_BIND_OPTS;

    m_lError = m_cMoniker.GetBindCtx()->GetBindOptions( pbind_optsLarge );
    if( FAILED( m_lError )) EXIT( L"Could not get large bind options" );

    // The returned structure should have the large cbStruct, 1s up to
    // the length of BIND_OPTS, and 0s after that.

    memset( pbind_optsExpected, 0, SIZE_OF_LARGE_BIND_OPTS );
    memset( pbind_optsExpected, 1, sizeof( bind_opts ));
    pbind_optsExpected->cbStruct = SIZE_OF_LARGE_BIND_OPTS;

    if( memcmp( pbind_optsLarge, pbind_optsExpected, SIZE_OF_LARGE_BIND_OPTS ))
      EXIT( L"Failed" );


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    DisplayErrors( bSuccess, L"CTest::GetOversizedBindOpts()" );
    return( bSuccess );

}   // CTest::GetOversizeBindOpts()



//+----------------------------------------------------------------
//
//  Function:   CTest::GetUndersizedBindOpts
//
//  Synopsis:   Create a bind context, and initialize the data in its
//              BIND_OPTS to 1s.  Create a normal BIND_OPTS-sized buffer,
//              initialize it to 2s, then use it to get a small-sized
//              BIND_OPTS from the bind context.  The resulting buffer
//              should have a small length, a small number of 1s,
//              and 2s for the remainder of the buffer.
//
//  Inputs:     None.
//
//  Outputs:    TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+----------------------------------------------------------------



BOOL CTest::GetUndersizedBindOpts( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    LPBIND_OPTS pbind_optsSmall    = (LPBIND_OPTS) new BYTE[ SIZE_OF_LARGE_BIND_OPTS ];
    LPBIND_OPTS pbind_optsExpected = (LPBIND_OPTS) new BYTE[ SIZE_OF_LARGE_BIND_OPTS ];
    BIND_OPTS   bind_opts;
    bind_opts.cbStruct = sizeof( bind_opts );

    //  -----
    //  Begin
    //  -----

    m_lError = 0L;

    wprintf( L"Get Undersized BindOpts\n" );
    wprintf( L"   Get the BIND_OPTS from a bind context, but only providing a small\n"
             L"   buffer, and verify that only that portion of the actual BIND_OPTS\n"
             L"   is returned.\n" );

    // Validate our 'new's.

    if( pbind_optsSmall == NULL )
        EXIT( L"Could not allocate pbind_optsSmall" );
    pbind_optsSmall->cbStruct = SIZE_OF_SMALL_BIND_OPTS;

    if( pbind_optsExpected == NULL )
        EXIT( L"Could not allocate pbind_optsExpected" );
    pbind_optsExpected->cbStruct = SIZE_OF_SMALL_BIND_OPTS;


    // Initialize the bind_opts (normal sized) in the bind context to 1s.

    if( !m_cMoniker.InitializeBindContext() )
        EXIT( L"Could not initialize the bind context" );

    memset( &bind_opts, 1, sizeof( bind_opts ));
    bind_opts.cbStruct = sizeof( bind_opts );;

    m_lError = m_cMoniker.GetBindCtx()->SetBindOptions( &bind_opts );
    if( FAILED( m_lError )) EXIT( L"Could not set original bind options" );


    // Initialize the small bind_opts to 2s, then retrieve the bind_opts into
    // this structure.

    memset( pbind_optsSmall, 2, SIZE_OF_LARGE_BIND_OPTS );
    pbind_optsSmall->cbStruct = SIZE_OF_SMALL_BIND_OPTS;

    m_lError = m_cMoniker.GetBindCtx()->GetBindOptions( pbind_optsSmall );
    if( FAILED( m_lError )) EXIT( L"Could not get small bind options" );

    // The returned structure should have the small cbStruct, 1s up to
    // the end of the small buffer, and 2s to the end of the real buffer.

    memset( pbind_optsExpected, 2, SIZE_OF_LARGE_BIND_OPTS );
    memset( pbind_optsExpected, 1, SIZE_OF_SMALL_BIND_OPTS );
    pbind_optsExpected->cbStruct = SIZE_OF_SMALL_BIND_OPTS;

    if( memcmp( pbind_optsSmall, pbind_optsExpected, SIZE_OF_LARGE_BIND_OPTS ))
        EXIT( L"Failed" );


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    DisplayErrors( bSuccess, L"CTest::GetUndersizedBindOpts()" );
    return( bSuccess );

}   // CTest::GetUndersizedBindOpts()


//+----------------------------------------------------------------
//
//  Function:   CTest::SetOversizedBindOpts
//
//  Synopsis:   Create a large BIND_OPTS buffer, set it in
//              a bind context, and verify that it can be read back.
//
//  Inputs:     None.
//
//  Outputs:    TRUE if successful, FALSE otherwise.
//
//  Effects:    None.
//
//+----------------------------------------------------------------

BOOL CTest::SetOversizedBindOpts( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    LPBIND_OPTS pbind_optsLarge    = (LPBIND_OPTS) new BYTE[ SIZE_OF_LARGE_BIND_OPTS ];
    LPBIND_OPTS pbind_optsExpected = (LPBIND_OPTS) new BYTE[ SIZE_OF_LARGE_BIND_OPTS ];

    //  -----
    //  Begin
    //  -----

    wprintf( L"Set Oversized BindOpts\n" );
    wprintf( L"   Set a larger-than-usual BIND_OPTS in a bind context, and verify\n"
             L"   that it can be read back in its entirety.\n" );

    // Validate our 'new's.

    if( pbind_optsLarge == NULL )
        EXIT( L"Could not allocate pbind_optsLarge" );
    pbind_optsLarge->cbStruct = SIZE_OF_LARGE_BIND_OPTS;

    if( pbind_optsExpected == NULL )
        EXIT( L"Could not allocate pbind_optsExpected" );
    pbind_optsExpected->cbStruct = SIZE_OF_LARGE_BIND_OPTS;

    // Initialize the large bind_opts to 1s, then set the large BIND_OPTS
    // into the bind context.

    if( !m_cMoniker.InitializeBindContext() )
        EXIT( L"Could not initialize the bind context" );

    memset( pbind_optsLarge, 1, SIZE_OF_LARGE_BIND_OPTS );
    pbind_optsLarge->cbStruct = SIZE_OF_LARGE_BIND_OPTS;

    m_lError = m_cMoniker.GetBindCtx()->SetBindOptions( pbind_optsLarge );
    if( FAILED( m_lError )) EXIT( L"Could not set large bind options" );

    // Get the BIND_OPTS back from the bind context, and verify that it's
    // what we set.

    memset( pbind_optsLarge, 0, SIZE_OF_LARGE_BIND_OPTS );
    pbind_optsLarge->cbStruct = SIZE_OF_LARGE_BIND_OPTS;
    m_lError = m_cMoniker.GetBindCtx()->GetBindOptions( pbind_optsLarge );

    memset( pbind_optsExpected, 1, SIZE_OF_LARGE_BIND_OPTS );
    pbind_optsExpected->cbStruct = SIZE_OF_LARGE_BIND_OPTS;

    if( memcmp( pbind_optsLarge, pbind_optsExpected, SIZE_OF_LARGE_BIND_OPTS ))
      EXIT( L"Failed" );


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    DisplayErrors( bSuccess, L"CTest::SetOversizedBindOpts()" );
    return( bSuccess );

}   // CTest::SetOversizeBindOpts()


//+------------------------------------------------------------
//
//  Function:   CTest::SetUndersizedBindOpts
//
//  Synopsis:   Create a bind context, and initialize its BIND_OPTS to
//              all 1s.  Then, set a small BIND_OPTS in the bind context
//              which is set to 2s.  Read back the whold BIND_OPTS, and
//              verify that it has the normal length, 2s at the
//              beginning, and 1s to the end.
//
//  Inputs:     None.
//
//  Output:     TRUE if successful, FALSE otherwise.
//
//+------------------------------------------------------------


BOOL CTest::SetUndersizedBindOpts( )
{
    //  ---------------
    //  Local Variables
    //  ---------------

    BOOL bSuccess = FALSE;

    BIND_OPTS bind_opts;
    BIND_OPTS bind_optsExpected;

    //  -----
    //  Begin
    //  -----

    m_lError = 0L;

    wprintf( L"Set Undersized BindOpts\n" );
    wprintf( L"   Initialize a BIND_OPTS in a bind context to 1s, then set a smaller\n"
             L"   BIND_OPTS in it set to 2s.  When the buffer is read back, it should\n"
             L"   have 2s up to the small buffer size, followed by 1s.\n" );

    // Initialize the bind context's BIND_OPTS (normal sized) to 1s.

    if( !m_cMoniker.InitializeBindContext() )
        EXIT( L"Could not initialize the bind context" );

    memset( &bind_opts, 1, sizeof( bind_opts ));
    bind_opts.cbStruct = sizeof( bind_opts );
    m_lError = m_cMoniker.GetBindCtx()->SetBindOptions( &bind_opts );
    if( FAILED( m_lError )) EXIT( L"Could not set initial BIND_OPTS" );

    // Now set a smaller BIND_OPTS.  But initialize the local BIND_OPTS to all
    // 2s, so that we can verify that only part of the buffer is put into the
    // bind context.

    memset( &bind_opts, 2, sizeof( bind_opts ) );
    bind_opts.cbStruct = SIZE_OF_SMALL_BIND_OPTS;
    m_lError = m_cMoniker.GetBindCtx()->SetBindOptions( &bind_opts );
    if( FAILED( m_lError )) EXIT( L"Could not set small BIND_OPTS" );

    // The resulting BIND_OPTS in the bind context should have 2s up
    // to SIZE_OF_SMALL_BIND_OPTS, and 1s for the remainder of the buffer.

    bind_opts.cbStruct = sizeof( bind_opts );
    m_lError = m_cMoniker.GetBindCtx()->GetBindOptions( &bind_opts );
    if( FAILED( m_lError )) EXIT( L"Could not get BIND_OPTS" );

    memset( &bind_optsExpected, 1, sizeof( bind_opts ));
    memset( &bind_optsExpected, 2, SIZE_OF_SMALL_BIND_OPTS );
    bind_optsExpected.cbStruct = sizeof( bind_opts );

    if( memcmp( &bind_opts, &bind_optsExpected, sizeof( bind_opts )))
      EXIT( L"Failed" );


    bSuccess = TRUE;

    //  ----
    //  Exit
    //  ----

Exit:

    DisplayErrors( bSuccess, L"CTest::SetUndersizedBindOpts()" );
    return( bSuccess );

}   // CTest::SetUndersizedBindOpts()


#ifdef _FUTURE_

BOOL CTest::CFMWithRegistryClear( )
{
    BOOL bSuccess = FALSE;
    WCHAR wszDisplayName[ MAX_PATH + sizeof( L'\0' ) ];

    if( !m_cMoniker.SaveRegistryTrackFlags() )
        EXIT( L"Could not save the existing track flags in the registry" );

    if( !m_cMoniker.DeleteRegistryTrackFlags() )
        EXIT( L"Could not delete the existing track flags in the registry" );

    if( !m_cMoniker.CreateFileMoniker() )
        EXIT( L"Could not CreateFileMoniker" );

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    if( !m_cMoniker.GetDisplayName( wszDisplayName ))
        EXIT( L"Could not get the display name" );

    if( !_wcsicmp( wszDisplayName, m_cMoniker.GetTemporaryStorageName() ))
        EXIT( L"Test failed:  A moniker was created using CreateFileMoniker, after\n"
              L"              the Track Flags had been cleared from the Registry.\n"
              L"              The underlying root storage was then renamed.\n"
              L"              But a GetDisplayName then showed the new name, implying\n"
              L"              that the created moniker is using tracking (which it\n"
              L"              should not, because without the Track Flags set there\n"
              L"              should be no tracking).\n" );
    

    bSuccess = TRUE;

Exit:

    m_cMoniker.DeleteTemporaryStorage();

    if( !m_cMoniker.RestoreRegistryTrackFlags() )
        ERROR_IN_EXIT( L"Could not restore Track Flags in Registry" );


    DisplayErrors( bSuccess, L"CTest::CFMWithRegistryClear" );
    return( bSuccess );

}   // CTest::CFMWithRegistryClear




BOOL CTest::CFMWithRegistrySet( )
{
    BOOL bSuccess = FALSE;
    WCHAR wszDisplayName[ MAX_PATH + sizeof( L'\0' ) ];

    if( !m_cMoniker.SaveRegistryTrackFlags() )
        EXIT( L"Could not save the existing track flags in the registry" );

    if( !m_cMoniker.SetTrackFlagsInRegistry( TRACK_LOCALONLY ) )
        EXIT( L"Could not set track flags in the registry" );

    if( !m_cMoniker.CreateFileMoniker() )
        EXIT( L"Could not CreateFileMoniker" );

    if( !m_cMoniker.RenameTemporaryStorage() )
        EXIT( L"Could not rename the temporary storage file" );

    if( !m_cMoniker.GetDisplayName( wszDisplayName ))
        EXIT( L"Could not get the display name" );

    if( _wcsicmp( wszDisplayName, m_cMoniker.GetTemporaryStorageName() ))
        EXIT( L"Test failed:  A moniker was created using CreateFileMoniker, after\n"
              L"              setting the TRACK_LOCALONLY flag in the Registry.\n"
              L"              However, after moving the linked file, GetDisplayName\n"
              L"              did not return the new name.\n" );
    

    bSuccess = TRUE;

Exit:

    m_cMoniker.DeleteTemporaryStorage();

    if( !m_cMoniker.RestoreRegistryTrackFlags() )
        ERROR_IN_EXIT( L"Could not restore Track Flags in Registry" );


    DisplayErrors( bSuccess, L"CTest::CFMWithRegistrySet()" );
    return( bSuccess );

}   // CTest::CFMWithRegistrySet


#endif // _FUTURE_