Changeset 782 in dev for branches/egtra


Ignore:
Timestamp:
Jan 29, 2011, 3:39:34 PM (14 years ago)
Author:
イグトランス (egtra)
Message:

アイコン読込のテストのコードを整理。

Location:
branches/egtra/ab5.0/abdev
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/egtra/ab5.0/abdev/ab-test/ab-test.cpp

    r781 r782  
    11#include "stdafx.h"
     2
     3#include <cstdint>
     4#include <cstring>
    25
    36#include <GdiPlus.h>
     
    69
    710#include <boost/test/unit_test.hpp>
     11
     12#include <boost/preprocessor/cat.hpp>
    813
    914#include <Resource/Load.h>
     
    2732typedef std::unique_ptr<HMODULE, HModuleDeleter> UniqueHModule;
    2833
     34template<typename F>
     35struct ScopeExitHolder
     36{   
     37    ScopeExitHolder(F f) : f(f) {}
     38
     39    ~ScopeExitHolder()
     40    {
     41        f();
     42    }
     43
     44private:
     45    F f;
     46
     47    ScopeExitHolder(ScopeExitHolder const&);
     48    ScopeExitHolder& operator =(ScopeExitHolder const&);
     49};
     50
     51#define AB_SCOPE_EXIT_2(f) auto BOOST_PP_CAT(AB_SCOPE_EXIT_FUNCTION_TEMP_, __LINE__) = (f); \
     52    ScopeExitHolder<decltype(BOOST_PP_CAT(AB_SCOPE_EXIT_FUNCTION_TEMP_, __LINE__))> BOOST_PP_CAT(AB_SCOPE_EXIT_FUNCTION_HOLDER_, __LINE__)_ (BOOST_PP_CAT(AB_SCOPE_EXIT_FUNCTION_TEMP_, __LINE__));
     53#define AB_SCOPE_EXIT(f) AB_SCOPE_EXIT_2([&]() f)
     54
     55template<typename F>
     56ScopeExitHolder<F> ScopeExit(F fn)
     57{
     58    return fn;
     59}
     60
     61#define GET_AT(bd, y, x) (*reinterpret_cast<DWORD const*>(static_cast<BYTE const*>((bd).Scan0) + (y) * bdL.Stride + (x) * sizeof (DWORD)))
     62
    2963bool IconEquals(HICON hiconL, HICON hiconR)
    3064{
     65    Gdiplus::Bitmap bmpL(hiconL), bmpR(hiconR);
     66
     67    if (bmpL.GetWidth() == bmpR.GetWidth()
     68        && bmpR.GetHeight() == bmpR.GetHeight())
     69    {
     70        Gdiplus::Rect rc(0, 0, bmpL.GetWidth(), bmpL.GetHeight());
     71        Gdiplus::BitmapData bdL = {}, bdR = {};
     72        BOOST_CHECK_EQUAL(bmpL.LockBits(&rc, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bdL), Gdiplus::Ok);
     73        BOOST_CHECK_EQUAL(bmpR.LockBits(&rc, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bdR), Gdiplus::Ok);
     74       
     75        AB_SCOPE_EXIT({bmpL.UnlockBits(&bdL);});
     76        AB_SCOPE_EXIT({bmpR.UnlockBits(&bdR);});
     77
     78        if (bdL.Width == bdR.Width && bdL.Height == bdR.Height)
     79        {
     80            for (UINT i = 0; i < bdL.Height; ++i)
     81            {
     82                if (std::memcmp(
     83                    static_cast<BYTE const*>(bdL.Scan0) + i * bdL.Stride,
     84                    static_cast<BYTE const*>(bdR.Scan0) + i * bdR.Stride,
     85                    bdL.Width * sizeof (std::uint32_t)) != 0)
     86                {
     87                    return false;
     88                }
     89            }
     90            return true;
     91        }
     92    }
    3193    return false;
    3294}
     
    3496BOOST_AUTO_TEST_CASE( ResourceLoading )
    3597{
     98    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
     99
     100    ULONG_PTR gdiplusToken;
     101    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
     102    AB_SCOPE_EXIT_2(std::bind(Gdiplus::GdiplusShutdown, gdiplusToken));
     103
    36104    TCHAR moduleName[MAX_PATH];
    37105    ::GetModuleFileName(nullptr, moduleName, MAX_PATH);
  • branches/egtra/ab5.0/abdev/ab-test/ab-test.vcxproj

    r781 r782  
    9191      <SubSystem>Console</SubSystem>
    9292      <GenerateDebugInformation>true</GenerateDebugInformation>
     93      <AdditionalDependencies>gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
    9394    </Link>
    9495  </ItemDefinitionGroup>
     
    103104      <SubSystem>Console</SubSystem>
    104105      <GenerateDebugInformation>true</GenerateDebugInformation>
     106      <AdditionalDependencies>gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
    105107    </Link>
    106108  </ItemDefinitionGroup>
     
    119121      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    120122      <OptimizeReferences>true</OptimizeReferences>
     123      <AdditionalDependencies>gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
    121124    </Link>
    122125  </ItemDefinitionGroup>
     
    135138      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    136139      <OptimizeReferences>true</OptimizeReferences>
     140      <AdditionalDependencies>gdiplus.lib;%(AdditionalDependencies)</AdditionalDependencies>
    137141    </Link>
    138142  </ItemDefinitionGroup>
  • branches/egtra/ab5.0/abdev/abdev-impl/Resource/Load.cpp

    r781 r782  
    99    auto pResource = LockResource(hMem);
    1010
    11     int idIcon = LookupIconIdFromDirectoryEx(reinterpret_cast<PBYTE>(pResource), TRUE, cxDesired, cyDesired, load);
     11    auto idIcon = LookupIconIdFromDirectoryEx(reinterpret_cast<PBYTE>(pResource), TRUE, cxDesired, cyDesired, load);
    1212    auto hrsrcIcon = FindResource(hinst, MAKEINTRESOURCE(idIcon), MAKEINTRESOURCE(RT_ICON));
    1313    auto hIconMem = LoadResource(hinst, hrsrcIcon);
     
    1515
    1616    return CreateIconFromResourceEx(reinterpret_cast<PBYTE>(pResourceIcon),
    17         SizeofResource(hinst, hrsrcIcon), TRUE, 0x00030000,
    18         cxDesired, cyDesired, load);
     17        SizeofResource(hinst, hrsrcIcon), TRUE, 0x00030000, cxDesired, cyDesired, load);
    1918}
    2019
Note: See TracChangeset for help on using the changeset viewer.