@@ -387,7 +387,7 @@ namespace Test::PickerCommonTests
387
387
}
388
388
}
389
389
390
- TEST_METHOD (VerifySuggestedFileName )
390
+ TEST_METHOD (VerifyValidateSuggestedFileName )
391
391
{
392
392
// Arrange.
393
393
auto test_cases = std::vector<std::tuple<winrt::hstring, bool >>{
@@ -431,6 +431,211 @@ namespace Test::PickerCommonTests
431
431
}
432
432
}
433
433
434
+ std::vector<std::tuple<winrt::hstring, bool >> cbsi_text_test_cases{
435
+ {L" Valid" , true }, // Valid commit button text
436
+ {L" " , true }, // Allow empty string
437
+ {L" Valid Text" , true }, // Allow spaces
438
+ {L" Invalid\0 Text" , false }, // Embedded null is invalid
439
+ };
440
+
441
+ TEST_METHOD (VerifyFolderPicker_ValidateCommitButtonText)
442
+ {
443
+ // Arrange.
444
+ winrt::Microsoft::UI::WindowId windowId{};
445
+ winrt::Microsoft::Windows::Storage::Pickers::FolderPicker picker (windowId);
446
+
447
+ // Act & Assert
448
+ for (const auto & test_case : cbsi_text_test_cases)
449
+ {
450
+ winrt::hstring commitButtonText = std::get<0 >(test_case);
451
+ bool expectValid = std::get<1 >(test_case);
452
+
453
+ if (expectValid)
454
+ {
455
+ picker.CommitButtonText (commitButtonText);
456
+ VERIFY_ARE_EQUAL (picker.CommitButtonText (), commitButtonText);
457
+ }
458
+ else
459
+ {
460
+ try
461
+ {
462
+ picker.CommitButtonText (commitButtonText);
463
+ std::wstring errorMessage = L" Expected exception for invalid commit button text: " + std::wstring (commitButtonText);
464
+ VERIFY_FAIL (errorMessage.c_str ());
465
+ }
466
+ catch (...)
467
+ {
468
+ // Expected exception for invalid commit button text
469
+ }
470
+ }
471
+ }
472
+ }
473
+
474
+ TEST_METHOD (VerifyFileOpenPicker_ValidateCommitButtonText)
475
+ {
476
+ // Arrange.
477
+ winrt::Microsoft::UI::WindowId windowId{};
478
+ winrt::Microsoft::Windows::Storage::Pickers::FileOpenPicker picker (windowId);
479
+
480
+ // Act & Assert
481
+ for (const auto & test_case : cbsi_text_test_cases)
482
+ {
483
+ winrt::hstring commitButtonText = std::get<0 >(test_case);
484
+ bool expectValid = std::get<1 >(test_case);
485
+
486
+ if (expectValid)
487
+ {
488
+ picker.CommitButtonText (commitButtonText);
489
+ VERIFY_ARE_EQUAL (picker.CommitButtonText (), commitButtonText);
490
+ }
491
+ else
492
+ {
493
+ try
494
+ {
495
+ picker.CommitButtonText (commitButtonText);
496
+ std::wstring errorMessage = L" Expected exception for invalid commit button text: " + std::wstring (commitButtonText);
497
+ VERIFY_FAIL (errorMessage.c_str ());
498
+ }
499
+ catch (...)
500
+ {
501
+ // Expected exception for invalid commit button text
502
+ }
503
+ }
504
+ }
505
+ }
506
+
507
+ TEST_METHOD (VerifyFileSavePicker_ValidateCommitButtonText)
508
+ {
509
+ // Arrange.
510
+ winrt::Microsoft::UI::WindowId windowId{};
511
+ winrt::Microsoft::Windows::Storage::Pickers::FileSavePicker picker (windowId);
512
+
513
+ // Act & Assert
514
+ for (const auto & test_case : cbsi_text_test_cases)
515
+ {
516
+ winrt::hstring commitButtonText = std::get<0 >(test_case);
517
+ bool expectValid = std::get<1 >(test_case);
518
+
519
+ if (expectValid)
520
+ {
521
+ picker.CommitButtonText (commitButtonText);
522
+ VERIFY_ARE_EQUAL (picker.CommitButtonText (), commitButtonText);
523
+ }
524
+ else
525
+ {
526
+ try
527
+ {
528
+ picker.CommitButtonText (commitButtonText);
529
+ std::wstring errorMessage = L" Expected exception for invalid commit button text: " + std::wstring (commitButtonText);
530
+ VERIFY_FAIL (errorMessage.c_str ());
531
+ }
532
+ catch (...)
533
+ {
534
+ // Expected exception for invalid commit button text
535
+ }
536
+ }
537
+ }
538
+ }
539
+
540
+ TEST_METHOD (VerifyFolderPicker_ValidateSettingsIdentifer)
541
+ {
542
+ // Arrange.
543
+ winrt::Microsoft::UI::WindowId windowId{};
544
+ winrt::Microsoft::Windows::Storage::Pickers::FolderPicker picker (windowId);
545
+
546
+ // Act & Assert
547
+ for (const auto & test_case : cbsi_text_test_cases)
548
+ {
549
+ winrt::hstring settingsIdentifier = std::get<0 >(test_case);
550
+ bool expectValid = std::get<1 >(test_case);
551
+
552
+ if (expectValid)
553
+ {
554
+ picker.SettingsIdentifier (settingsIdentifier);
555
+ VERIFY_ARE_EQUAL (picker.SettingsIdentifier (), settingsIdentifier);
556
+ }
557
+ else
558
+ {
559
+ try
560
+ {
561
+ picker.SettingsIdentifier (settingsIdentifier);
562
+ std::wstring errorMessage = L" Expected exception for invalid commit button text: " + std::wstring (settingsIdentifier);
563
+ VERIFY_FAIL (errorMessage.c_str ());
564
+ }
565
+ catch (...)
566
+ {
567
+ // Expected exception for invalid commit button text
568
+ }
569
+ }
570
+ }
571
+ }
572
+
573
+ TEST_METHOD (VerifyFileOpenPicker_ValidateSettingsIdentifier)
574
+ {
575
+ // Arrange.
576
+ winrt::Microsoft::UI::WindowId windowId{};
577
+ winrt::Microsoft::Windows::Storage::Pickers::FileOpenPicker picker (windowId);
578
+
579
+ // Act & Assert
580
+ for (const auto & test_case : cbsi_text_test_cases)
581
+ {
582
+ winrt::hstring settingsIdentifier = std::get<0 >(test_case);
583
+ bool expectValid = std::get<1 >(test_case);
584
+
585
+ if (expectValid)
586
+ {
587
+ picker.SettingsIdentifier (settingsIdentifier);
588
+ VERIFY_ARE_EQUAL (picker.SettingsIdentifier (), settingsIdentifier);
589
+ }
590
+ else
591
+ {
592
+ try
593
+ {
594
+ picker.SettingsIdentifier (settingsIdentifier);
595
+ std::wstring errorMessage = L" Expected exception for invalid commit button text: " + std::wstring (settingsIdentifier);
596
+ VERIFY_FAIL (errorMessage.c_str ());
597
+ }
598
+ catch (...)
599
+ {
600
+ // Expected exception for invalid commit button text
601
+ }
602
+ }
603
+ }
604
+ }
605
+
606
+ TEST_METHOD (VerifyFileSavePicker_ValidateSettingsIdentifier)
607
+ {
608
+ // Arrange.
609
+ winrt::Microsoft::UI::WindowId windowId{};
610
+ winrt::Microsoft::Windows::Storage::Pickers::FileSavePicker picker (windowId);
611
+
612
+ // Act & Assert
613
+ for (const auto & test_case : cbsi_text_test_cases)
614
+ {
615
+ winrt::hstring settingsIdentifier = std::get<0 >(test_case);
616
+ bool expectValid = std::get<1 >(test_case);
617
+
618
+ if (expectValid)
619
+ {
620
+ picker.SettingsIdentifier (settingsIdentifier);
621
+ VERIFY_ARE_EQUAL (picker.SettingsIdentifier (), settingsIdentifier);
622
+ }
623
+ else
624
+ {
625
+ try
626
+ {
627
+ picker.SettingsIdentifier (settingsIdentifier);
628
+ std::wstring errorMessage = L" Expected exception for invalid commit button text: " + std::wstring (settingsIdentifier);
629
+ VERIFY_FAIL (errorMessage.c_str ());
630
+ }
631
+ catch (...)
632
+ {
633
+ // Expected exception for invalid commit button text
634
+ }
635
+ }
636
+ }
637
+ }
638
+
434
639
std::vector<std::tuple<winrt::hstring, bool >> file_extension_validation_test_cases{
435
640
{L" .txt" , true },
436
641
{L" *" , true }, // One asterisk is valid
0 commit comments