|
28 | 28 | #pragma warning( pop ) |
29 | 29 |
|
30 | 30 | #include "TestWin32Utils.h" |
| 31 | +#include "Icon.h" |
31 | 32 | #include "Win32Utils.h" |
32 | 33 | #include "ArgumentsHandler.h" |
33 | 34 |
|
@@ -652,6 +653,68 @@ namespace shellanything |
652 | 653 | } |
653 | 654 | } |
654 | 655 | //-------------------------------------------------------------------------------------------------- |
| 656 | + TEST_F(TestWin32Utils, testNegativeIconIndexIssue155) // Issue #155 |
| 657 | + { |
| 658 | + Icon icon; |
| 659 | + |
| 660 | + // On my system, with current implementation, |
| 661 | + // Icon::ResolveFileExtensionIcon() resolves HTML file extension to the following: |
| 662 | + icon.SetPath("C:\\Program Files\\Internet Explorer\\iexplore.exe"); |
| 663 | + icon.SetIndex(-17); |
| 664 | + |
| 665 | + // act, load an icon with negative index |
| 666 | + HBITMAP hBitmap = Win32Utils::LoadIconFromFileAsBitmap32Bpp(icon.GetPath().c_str(), icon.GetIndex()); |
| 667 | + ASSERT_NE(hBitmap, Win32Utils::INVALID_BITMAP_HANDLE); |
| 668 | + |
| 669 | + // build output files |
| 670 | + std::string test_dir = ra::filesystem::GetTemporaryDirectory(); |
| 671 | + ASSERT_TRUE(ra::filesystem::CreateDirectory(test_dir.c_str())); |
| 672 | + std::string bitmap_filename = ra::testing::GetTestQualifiedName() + ".bmp"; |
| 673 | + std::string output_path = test_dir + "\\" + bitmap_filename; |
| 674 | + |
| 675 | + // remove data from previous runs |
| 676 | + ra::filesystem::DeleteFile(output_path.c_str()); |
| 677 | + |
| 678 | + // Save as *.bmp |
| 679 | + bool saved = Win32Utils::SaveBitmapFile(output_path.c_str(), hBitmap); |
| 680 | + ASSERT_TRUE(saved) << "Failed to save bitmap to file: " << output_path; |
| 681 | + |
| 682 | + // Cleanup |
| 683 | + DeleteObject(hBitmap); |
| 684 | + } |
| 685 | + //-------------------------------------------------------------------------------------------------- |
| 686 | + TEST_F(TestWin32Utils, testNegativeIconIndexIssue164) // Issue #164 |
| 687 | + { |
| 688 | + Icon icon; |
| 689 | + |
| 690 | + // On my system, Icon::ResolveFileExtensionIcon() resolves 'txt' file extension to a negative icon index |
| 691 | + icon.SetFileExtension("txt"); |
| 692 | + icon.ResolveFileExtensionIcon(); |
| 693 | + |
| 694 | + ASSERT_TRUE(icon.IsValid()); |
| 695 | + ASSERT_TRUE(icon.GetIndex() < 1); |
| 696 | + |
| 697 | + // act, load an icon with negative index |
| 698 | + HBITMAP hBitmap = Win32Utils::LoadIconFromFileAsBitmap32Bpp(icon.GetPath().c_str(), icon.GetIndex()); |
| 699 | + ASSERT_NE(hBitmap, Win32Utils::INVALID_BITMAP_HANDLE); |
| 700 | + |
| 701 | + // build output files |
| 702 | + std::string test_dir = ra::filesystem::GetTemporaryDirectory(); |
| 703 | + ASSERT_TRUE(ra::filesystem::CreateDirectory(test_dir.c_str())); |
| 704 | + std::string bitmap_filename = ra::testing::GetTestQualifiedName() + ".bmp"; |
| 705 | + std::string output_path = test_dir + "\\" + bitmap_filename; |
| 706 | + |
| 707 | + // remove data from previous runs |
| 708 | + ra::filesystem::DeleteFile(output_path.c_str()); |
| 709 | + |
| 710 | + // Save as *.bmp |
| 711 | + bool saved = Win32Utils::SaveBitmapFile(output_path.c_str(), hBitmap); |
| 712 | + ASSERT_TRUE(saved) << "Failed to save bitmap to file: " << output_path; |
| 713 | + |
| 714 | + // Cleanup |
| 715 | + DeleteObject(hBitmap); |
| 716 | + } |
| 717 | + //-------------------------------------------------------------------------------------------------- |
655 | 718 |
|
656 | 719 | } //namespace test |
657 | 720 | } //namespace shellanything |
0 commit comments