"Fossies" - the Fresh Open Source Software Archive

Member "libgdiplus-6.0.2/tests/testmetafile.c" (31 Jul 2019, 22799 Bytes) of package /linux/misc/mono-sources/libgdiplus/libgdiplus-6.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #ifdef WIN32
    2 #ifndef __cplusplus
    3 #error Please compile with a C++ compiler.
    4 #endif
    5 #endif
    6 
    7 #if defined(USE_WINDOWS_GDIPLUS)
    8 #include <Windows.h>
    9 #include <GdiPlus.h>
   10 
   11 #pragma comment(lib, "gdiplus.lib")
   12 #else
   13 #include <GdiPlusFlat.h>
   14 #endif
   15 
   16 #if defined(USE_WINDOWS_GDIPLUS)
   17 using namespace Gdiplus;
   18 using namespace DllExports;
   19 #endif
   20 
   21 #include <assert.h>
   22 #include <stdio.h>
   23 #include <stdlib.h>
   24 #include "testhelpers.h"
   25 
   26 static WCHAR wmfFilePath[] = {'t', 'e', 's', 't', '.', 'w', 'm', 'f', 0};
   27 static WCHAR emfFilePath[] = {'t', 'e', 's', 't', '.', 'e', 'm', 'f', 0};
   28 
   29 static void test_createMetafileFromFile ()
   30 {
   31     GpStatus status;
   32     WCHAR *noSuchFilePath;
   33     WCHAR *invalidFilePath;
   34     WCHAR *bitmapFilePath;
   35     GpMetafile *metafile;
   36 
   37     noSuchFilePath = createWchar ("noSuchFile.wmf");
   38     invalidFilePath = createWchar ("test.ttf");
   39     bitmapFilePath = createWchar ("test.bmp");
   40 
   41     // Create from WMF file.
   42     status = GdipCreateMetafileFromFile (wmfFilePath, &metafile);
   43     assertEqualInt (status, Ok);
   44     // FIXME: GDI+ converts wmf files to emf.
   45 #if defined(USE_WINDOWS_GDIPLUS)
   46     verifyImage(metafile, ImageTypeMetafile, emfRawFormat, PixelFormat32bppRGB, 0, 0, 2, 2, 0.017323f, 0.016807f, 0.458334f, 0.444445f, 327683, 0, TRUE);
   47 #endif
   48     GdipDisposeImage (metafile);
   49 
   50     // Create from EMF file.
   51     status = GdipCreateMetafileFromFile (emfFilePath, &metafile);
   52     assertEqualInt (status, Ok);
   53     verifyMetafile (metafile, emfRawFormat, 0, 0, 100, 100, 1944.444336f, 1888.888794f);
   54     GdipDisposeImage (metafile);
   55 
   56     // Negative tests.
   57     status = GdipCreateMetafileFromFile (NULL, &metafile);
   58     assertEqualInt (status, InvalidParameter);
   59 
   60     status = GdipCreateMetafileFromFile (noSuchFilePath, NULL);
   61     assertEqualInt (status, InvalidParameter);
   62 
   63     status = GdipCreateMetafileFromFile (noSuchFilePath, &metafile);
   64     assertEqualInt (status, GenericError);
   65 
   66     status = GdipCreateMetafileFromFile (invalidFilePath, &metafile);
   67     assertEqualInt (status, GenericError);
   68 
   69     status = GdipCreateMetafileFromFile (bitmapFilePath, &metafile);
   70     assertEqualInt (status, GenericError);
   71 }
   72 
   73 static void test_createMetafileFromStream ()
   74 {
   75     GpStatus status;
   76     GpMetafile *metafile;
   77 #if !defined(USE_WINDOWS_GDIPLUS)
   78     int temp = 0;
   79 #endif
   80 
   81     // Negative tests.
   82     status = GdipCreateMetafileFromStream (NULL, &metafile);
   83     assertEqualInt (status, InvalidParameter);
   84 
   85     // Libgdiplus does not implement GdipCreateMetafileFromStream.
   86 #if !defined(USE_WINDOWS_GDIPLUS)
   87     status = GdipCreateMetafileFromStream (&temp, NULL);
   88     assertEqualInt (status, InvalidParameter);
   89 
   90     status = GdipCreateMetafileFromStream (&temp, &metafile);
   91     assertEqualInt (status, NotImplemented);
   92 #endif
   93 }
   94 
   95 static void test_createMetafileFromEmf ()
   96 {
   97     GpStatus status;
   98     GpMetafile *wmfMetafile;
   99     GpMetafile *emfMetafile;
  100     GpMetafile *metafile;
  101     HENHMETAFILE hWmfMetafile;
  102     HENHMETAFILE hEmfMetafile;
  103 
  104     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  105     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  106 #if defined(USE_WINDOWS_GDIPLUS)
  107     HDC wmfHdc = CreateMetaFileA (NULL);
  108     hWmfMetafile = (HENHMETAFILE) CloseMetaFile (wmfHdc);
  109     CopyMetaFileA ((HMETAFILE) hWmfMetafile, "test.wmf");
  110 #else
  111     GdipGetHemfFromMetafile (wmfMetafile, &hWmfMetafile);
  112 #endif
  113     GdipGetHemfFromMetafile (emfMetafile, &hEmfMetafile);
  114 
  115     // Create from a WMF file.
  116     metafile = (GpMetafile *) 0xCC;
  117     status = GdipCreateMetafileFromEmf (hWmfMetafile, TRUE, &metafile);
  118     assertEqualInt (status, GenericError);
  119     assert (!metafile);
  120 
  121     metafile = (GpMetafile *) 0xCC;
  122     status = GdipCreateMetafileFromEmf (hWmfMetafile, FALSE, &metafile);
  123     assertEqualInt (status, GenericError);
  124     assert (!metafile);
  125 
  126     // Create from a EMF file.
  127     status = GdipCreateMetafileFromEmf (hEmfMetafile, FALSE, &metafile);
  128     assertEqualInt (status, Ok);
  129     verifyMetafile (metafile, emfRawFormat, 0, 0, 100, 100, 1944.444336f, 1888.888794f);
  130     GdipDisposeImage (metafile);
  131 
  132     status = GdipCreateMetafileFromEmf (hEmfMetafile, TRUE, &metafile);
  133     assertEqualInt (status, Ok);
  134     verifyMetafile (metafile, emfRawFormat, 0, 0, 100, 100, 1944.444336f, 1888.888794f);
  135     GdipDisposeImage (metafile);
  136 
  137     // Negative tests.
  138     status = GdipCreateMetafileFromEmf (NULL, TRUE, &metafile);
  139     assertEqualInt (status, InvalidParameter);
  140 
  141     status = GdipCreateMetafileFromEmf (hEmfMetafile, TRUE, NULL);
  142     assertEqualInt (status, InvalidParameter);
  143 
  144     GdipDisposeImage (wmfMetafile);
  145     GdipDisposeImage (emfMetafile);
  146 }
  147 
  148 static void test_createMetafileFromWmf ()
  149 {
  150     GpStatus status;
  151     GpMetafile *wmfMetafile;
  152     GpMetafile *emfMetafile;
  153     WmfPlaceableFileHeader wmfPlaceableFileHeader;
  154     GpMetafile *metafile;
  155     HMETAFILE hWmfMetafile;
  156     HMETAFILE hEmfMetafile;
  157 
  158     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  159     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  160 #if defined(USE_WINDOWS_GDIPLUS)
  161     HDC wmfHdc = CreateMetaFileA (NULL);
  162     hWmfMetafile = CloseMetaFile (wmfHdc);
  163     CopyMetaFileA (hWmfMetafile, "test.wmf");
  164 #else
  165     GdipGetHemfFromMetafile (wmfMetafile, &hWmfMetafile);
  166 #endif
  167     GdipGetHemfFromMetafile (emfMetafile, (HENHMETAFILE *) &hEmfMetafile);
  168 
  169     // Create from WMF file - no placeable header.
  170     status = GdipCreateMetafileFromWmf (hWmfMetafile, FALSE, NULL, &metafile);
  171     assertEqualInt (status, Ok);
  172     // FIXME: GDI+ converts wmf files to emf.
  173 #if defined(USE_WINDOWS_GDIPLUS)
  174     verifyImage(metafile, ImageTypeMetafile, emfRawFormat, PixelFormat32bppRGB, 0, 0, 2, 2, 0.017323f, 0.016807f, 0.458334f, 0.444445f, 327683, 0, TRUE);
  175 #endif
  176     GdipDisposeImage (metafile);
  177 
  178     status = GdipCreateMetafileFromWmf (hWmfMetafile, TRUE, NULL, &metafile);
  179     assertEqualInt (status, Ok);
  180     // FIXME: GDI+ converts wmf files to emf.
  181 #if defined(USE_WINDOWS_GDIPLUS)
  182     verifyImage(metafile, ImageTypeMetafile, emfRawFormat, PixelFormat32bppRGB, 0, 0, 2, 2, 0.017323f, 0.016807f, 0.458334f, 0.444445f, 327683, 0, TRUE);
  183 #endif
  184     GdipDisposeImage (metafile);
  185 
  186     // Create from EMF file.
  187     metafile = (GpMetafile *) 0xCC;
  188     status = GdipCreateMetafileFromWmf (hEmfMetafile, TRUE, &wmfPlaceableFileHeader, &metafile);
  189     assertEqualInt (status, GenericError);
  190     assert (!metafile);
  191 
  192     metafile = (GpMetafile *) 0xCC;
  193     status = GdipCreateMetafileFromWmf (hEmfMetafile, FALSE, &wmfPlaceableFileHeader, &metafile);
  194     assertEqualInt (status, GenericError);
  195     assert (!metafile);
  196 
  197     // Negative tests.
  198     status = GdipCreateMetafileFromWmf (NULL, TRUE, &wmfPlaceableFileHeader, &metafile);
  199     assertEqualInt (status, InvalidParameter);
  200 
  201     status = GdipCreateMetafileFromWmf (hWmfMetafile, TRUE, &wmfPlaceableFileHeader, NULL);
  202     assertEqualInt (status, InvalidParameter);
  203 
  204     GdipDisposeImage (wmfMetafile);
  205     GdipDisposeImage (emfMetafile);
  206 }
  207 
  208 static void test_getMetafileHeaderFromWmf ()
  209 {
  210 #if !defined(USE_WINDOWS_GDIPLUS)
  211     GpStatus status;
  212     GpMetafile *wmfMetafile;
  213     GpMetafile *emfMetafile;
  214     WmfPlaceableFileHeader wmfPlaceableFileHeader;
  215     MetafileHeader header;
  216     HMETAFILE hWmfMetafile;
  217     HMETAFILE hEmfMetafile;
  218 
  219     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  220     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  221 #if defined(USE_WINDOWS_GDIPLUS)
  222     HDC wmfHdc = CreateMetaFileA (NULL);
  223     hWmfMetafile = CloseMetaFile (wmfHdc);
  224     CopyMetaFileA (hWmfMetafile, "test.wmf");
  225 #else
  226     GdipGetHemfFromMetafile (wmfMetafile, &hWmfMetafile);
  227 #endif
  228     GdipGetHemfFromMetafile (emfMetafile, (HENHMETAFILE *) &hEmfMetafile);
  229 
  230     // Get from WMF file.
  231     status = GdipGetMetafileHeaderFromWmf (hWmfMetafile, &wmfPlaceableFileHeader, &header);
  232     assertEqualInt (status, Ok);
  233     assertEqualInt (header.Type, 2);
  234     assertEqualInt (header.Size, 68142);
  235     assertEqualInt (header.Version, 768);
  236     assertEqualInt (header.EmfPlusFlags, 0);
  237 
  238     // FIXME: these values constantly fluctuate with libgdiplus - potential UB?
  239 #if defined(USE_WINDOWS_GDIPLUS)
  240     assertEqualInt (header.DpiX, 0);
  241     assertEqualInt (header.DpiY, 0);
  242     assertEqualInt (header.X, 0);
  243     assertEqualInt (header.Y, 0);
  244     assertEqualInt (header.Width, 0);
  245     assertEqualInt (header.Height, 0);
  246 #endif
  247 
  248     // Get from EMF file.
  249     status = GdipGetMetafileHeaderFromWmf (hEmfMetafile, &wmfPlaceableFileHeader, &header);
  250     assertEqualInt (status, Ok);
  251     assertEqualInt (header.Type , 2);
  252     assertEqualInt (header.Size, 0);
  253     assertEqualInt (header.Version,  108);
  254     assertEqualInt (header.EmfPlusFlags, 0);
  255     // FIXME: these values constantly fluctuate with libgdiplus - potential UB?
  256 #if defined(USE_WINDOWS_GDIPLUS)
  257     assert (header.DpiX > 0);
  258     assert (header.DpiY > 0);
  259     assertEqualInt (header.X, 0);
  260     assertEqualInt (header.Y, 0);
  261     assertEqualInt (header.Width, 0);
  262     assertEqualInt (header.Height, 0);
  263 #endif
  264 
  265     // Negative tests.
  266     status = GdipGetMetafileHeaderFromWmf (NULL, &wmfPlaceableFileHeader, &header);
  267     assertEqualInt (status, InvalidParameter);
  268 
  269     status = GdipGetMetafileHeaderFromWmf (hWmfMetafile, NULL, &header);
  270     assertEqualInt (status, InvalidParameter);
  271 
  272     status = GdipGetMetafileHeaderFromWmf (hWmfMetafile, &wmfPlaceableFileHeader, NULL);
  273     assertEqualInt (status, InvalidParameter);
  274 
  275     GdipDisposeImage (wmfMetafile);
  276     GdipDisposeImage (emfMetafile);
  277 #endif
  278 }
  279 
  280 static void test_getMetafileHeaderFromEmf ()
  281 {
  282     GpStatus status;
  283     GpMetafile *wmfMetafile;
  284     GpMetafile *emfMetafile;
  285     HENHMETAFILE hWmfMetafile;
  286     HENHMETAFILE hEmfMetafile;
  287     MetafileHeader header;
  288 
  289     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  290     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  291 #if defined(USE_WINDOWS_GDIPLUS)
  292     HDC wmfHdc = CreateMetaFileA (NULL);
  293     hWmfMetafile = (HENHMETAFILE) CloseMetaFile (wmfHdc);
  294     CopyMetaFileA ((HMETAFILE) hWmfMetafile, "test.wmf");
  295 #else
  296     GdipGetHemfFromMetafile (wmfMetafile, &hWmfMetafile);
  297 #endif
  298     GdipGetHemfFromMetafile (emfMetafile, &hEmfMetafile);
  299 
  300     // Get from EMF file.
  301     status = GdipGetMetafileHeaderFromEmf (hEmfMetafile, &header);
  302     assertEqualInt (status, Ok);
  303     assertEqualInt (header.Type, 3);
  304     assertEqualInt (header.Size, 30284);
  305     assertEqualInt (header.Version, 65536);
  306     assertEqualInt (header.EmfPlusFlags, 0);
  307     assert (header.DpiX > 0);
  308     assert (header.DpiY > 0);
  309     assertEqualInt (header.X, 0);
  310     assertEqualInt (header.Y, 0);
  311     assertEqualInt (header.Width, 100);
  312     assertEqualInt (header.Height, 100);
  313     assertEqualInt (header.EmfPlusHeaderSize, 0);
  314 
  315     // Get from WMF file.
  316     status = GdipGetMetafileHeaderFromEmf (hWmfMetafile, &header);
  317     assertEqualInt (status, InvalidParameter);
  318 
  319     // Negative tests.
  320     status = GdipGetMetafileHeaderFromEmf (NULL, &header);
  321     assertEqualInt (status, InvalidParameter);
  322 
  323     // This causes GDI+ to crash.
  324 #if !defined(USE_WINDOWS_GDIPLUS)
  325     status = GdipGetMetafileHeaderFromEmf (hWmfMetafile, NULL);
  326     assertEqualInt (status, InvalidParameter);
  327 #endif
  328 
  329     GdipDisposeImage (wmfMetafile);
  330     GdipDisposeImage (emfMetafile);
  331 }
  332 
  333 static void test_getMetafileHeaderFromFile ()
  334 {
  335     GpStatus status;
  336     MetafileHeader header;
  337 
  338     // Get from WMF file.
  339     status = GdipGetMetafileHeaderFromFile (wmfFilePath, &header);
  340     assertEqualInt (status, Ok);
  341     // FIXME: GDI+ converts wmf files to emf.
  342 #if defined(USE_WINDOWS_GDIPLUS)
  343     assertEqualInt (header.Type, MetafileTypeEmf);
  344     assertEqualInt (header.Size, 256);
  345     assertEqualInt (header.Version, 65536);
  346     assertEqualInt (header.EmfPlusFlags, 0);
  347     assertEqualFloat (header.DpiX, 95.9999924);
  348     assertEqualFloat (header.DpiY, 96.0504150);
  349     assertEqualInt (header.X, -1);
  350     assertEqualInt (header.Y, -1);
  351     assertEqualInt (header.Width, 2);
  352     assertEqualInt (header.Height, 2);
  353 #endif
  354 
  355     // Get from EMF file.
  356     status = GdipGetMetafileHeaderFromFile (emfFilePath, &header);
  357     assertEqualInt (status, Ok);
  358     assertEqualInt (header.Type, MetafileTypeEmf);
  359     assertEqualInt (header.Size, 30284);
  360     assertEqualInt (header.Version, 65536);
  361     assertEqualInt (header.EmfPlusFlags, 0);
  362     assertEqualFloat (header.DpiX, 130.628555f);
  363     assertEqualFloat (header.DpiY, 134.470581f);
  364     assertEqualInt (header.X, 0);
  365     assertEqualInt (header.Y, 0);
  366     assertEqualInt (header.Width, 100);
  367     assertEqualInt (header.Height, 100);
  368     assertEqualInt (header.EmfPlusHeaderSize, 0);
  369 
  370     // Negative tests.
  371     status = GdipGetMetafileHeaderFromFile (NULL, &header);
  372     assertEqualInt (status, InvalidParameter);
  373 
  374     // This causes GDI+ to crash.
  375 #if !defined(USE_WINDOWS_GDIPLUS)
  376     status = GdipGetMetafileHeaderFromFile (wmfFilePath, NULL);
  377     assertEqualInt (status, InvalidParameter);
  378 #endif
  379 }
  380 
  381 static void test_getMetafileHeaderFromStream ()
  382 {
  383     GpStatus status;
  384     MetafileHeader header;
  385 #if !defined(USE_WINDOWS_GDIPLUS)
  386     int temp = 0;
  387 #endif
  388 
  389     // Negative tests.
  390     status = GdipGetMetafileHeaderFromStream (NULL, &header);
  391     assertEqualInt (status, InvalidParameter);
  392 
  393     // Libgdiplus does not implement GdipGetMetafileHeaderFromStream.
  394 #if !defined(USE_WINDOWS_GDIPLUS)
  395     status = GdipGetMetafileHeaderFromStream (&temp, NULL);
  396     assertEqualInt (status, InvalidParameter);
  397 
  398     status = GdipGetMetafileHeaderFromStream (&temp, &header);
  399     assertEqualInt (status, NotImplemented);
  400 #endif
  401 }
  402 
  403 static void test_getMetafileHeaderFromMetafile ()
  404 {
  405     GpStatus status;
  406     GpMetafile *wmfMetafile;
  407     GpMetafile *emfMetafile;
  408     MetafileHeader header;
  409 
  410     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  411     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  412 
  413     // Get from WMF file.
  414     status = GdipGetMetafileHeaderFromMetafile (wmfMetafile, &header);
  415     assertEqualInt (status, Ok);
  416     // FIXME: GDI+ converts wmf files to emf.
  417 #if defined(USE_WINDOWS_GDIPLUS)
  418     assertEqualInt (header.Type, MetafileTypeEmf);
  419     assertEqualInt (header.Size, 256);
  420     assertEqualInt (header.Version, 65536);
  421     assertEqualInt (header.EmfPlusFlags, 0);
  422     assertEqualFloat (header.DpiX, 95.9999924);
  423     assertEqualFloat (header.DpiY, 96.0504150);
  424     assertEqualInt (header.X, -1);
  425     assertEqualInt (header.Y, -1);
  426     assertEqualInt (header.Width, 2);
  427     assertEqualInt (header.Height, 2);
  428 #endif
  429 
  430     // Get from EMF file.
  431     status = GdipGetMetafileHeaderFromMetafile (emfMetafile, &header);
  432     assertEqualInt (status, Ok);
  433     assertEqualInt (header.Type, MetafileTypeEmf);
  434     assertEqualInt (header.Size, 30284);
  435     assertEqualInt (header.Version, 65536);
  436     assertEqualInt (header.EmfPlusFlags, 0);
  437     assertEqualFloat (header.DpiX, 130.628555f);
  438     assertEqualFloat (header.DpiY, 134.470581f);
  439     assertEqualInt (header.X, 0);
  440     assertEqualInt (header.Y, 0);
  441     assertEqualInt (header.Width, 100);
  442     assertEqualInt (header.Height, 100);
  443     assertEqualInt (header.EmfPlusHeaderSize, 0);
  444 
  445     // Negative tests.
  446     status = GdipGetMetafileHeaderFromMetafile (NULL, &header);
  447     assertEqualInt (status, InvalidParameter);
  448 
  449     // This causes GDI+ to crash.
  450 #if !defined(USE_WINDOWS_GDIPLUS)
  451     status = GdipGetMetafileHeaderFromMetafile (emfMetafile, NULL);
  452     assertEqualInt (status, InvalidParameter);
  453 #endif
  454 
  455     GdipDisposeImage (wmfMetafile);
  456     GdipDisposeImage (emfMetafile);
  457 }
  458 
  459 static void test_gettHemfFromMetafile ()
  460 {
  461     GpStatus status;
  462     GpMetafile *wmfMetafile;
  463     GpMetafile *emfMetafile;
  464     HENHMETAFILE hEmfMetafile;
  465     GpMetafile *metafileFromEmf;
  466     HENHMETAFILE hemf;
  467 
  468     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  469     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  470     GdipGetHemfFromMetafile (emfMetafile, &hEmfMetafile);
  471     GdipCreateMetafileFromEmf (hEmfMetafile, FALSE, &metafileFromEmf);
  472 
  473     // The definition of HENHMETAFILE is different between libgdiplus and GDI+.
  474 #if !defined(USE_WINDOWS_GDIPLUS)
  475     // Get from WMF file.
  476     status = GdipGetHemfFromMetafile (wmfMetafile, &hemf);
  477     assertEqualInt (status, Ok);
  478     assert (hemf == wmfMetafile);
  479 
  480     // Get from EMF file.
  481     status = GdipGetHemfFromMetafile (emfMetafile, &hemf);
  482     assertEqualInt (status, Ok);
  483     assert (hemf == emfMetafile);
  484 
  485     // Get from EMF file from EMF file.
  486     status = GdipGetHemfFromMetafile (metafileFromEmf, &hemf);
  487     assertEqualInt (status, Ok);
  488     assert (hemf == metafileFromEmf);
  489 
  490     status = GdipGetHemfFromMetafile (metafileFromEmf, &hemf);
  491     assertEqualInt (status, Ok);
  492     assert (hemf == metafileFromEmf);
  493 #endif
  494 
  495     // Negative tests.
  496     status = GdipGetHemfFromMetafile (NULL, &hemf);
  497     assertEqualInt (status, InvalidParameter);
  498 
  499     status = GdipGetHemfFromMetafile (NULL, &hemf);
  500     assertEqualInt (status, InvalidParameter);
  501 
  502     GdipDisposeImage (wmfMetafile);
  503     GdipDisposeImage (emfMetafile);
  504     GdipDisposeImage (metafileFromEmf);
  505 }
  506 
  507 static void test_getMetafileDownLevelRasterizationLimit ()
  508 {
  509     GpStatus status;
  510     GpMetafile *wmfMetafile;
  511     GpMetafile *emfMetafile;
  512     UINT metafileRasterizationLimitDpi;
  513 
  514     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  515     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  516 
  517     // Get from EMF file.
  518     // FIXME: GDI+ returns WrongState.
  519 #if defined(USE_WINDOWS_GDIPLUS)
  520     status = GdipGetMetafileDownLevelRasterizationLimit (emfMetafile, &metafileRasterizationLimitDpi);
  521     assertEqualInt (status, WrongState);
  522 #endif
  523 
  524     // Get from WMF file.
  525     status = GdipGetMetafileDownLevelRasterizationLimit (wmfMetafile, &metafileRasterizationLimitDpi);
  526     assertEqualInt (status, WrongState);
  527 
  528     // Negative tests.
  529     status = GdipGetMetafileDownLevelRasterizationLimit (NULL, &metafileRasterizationLimitDpi);
  530     assertEqualInt (status, InvalidParameter);
  531 
  532     status = GdipGetMetafileDownLevelRasterizationLimit (emfMetafile, NULL);
  533     assertEqualInt (status, InvalidParameter);
  534 
  535     GdipDisposeImage (wmfMetafile);
  536     GdipDisposeImage (emfMetafile);
  537 }
  538 
  539 static void test_setMetafileDownLevelRasterizationLimit ()
  540 {
  541     GpStatus status;
  542     GpMetafile *emfMetafile;
  543     GpMetafile *wmfMetafile;
  544 
  545     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  546     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  547 
  548     // Get from EMF file.
  549     // FIXME: GDI+ returns InvalidParameter/WrongState.
  550 #if defined(USE_WINDOWS_GDIPLUS)
  551     status = GdipSetMetafileDownLevelRasterizationLimit (emfMetafile, 5);
  552     assertEqualInt (status, InvalidParameter);
  553 #
  554     status = GdipSetMetafileDownLevelRasterizationLimit (emfMetafile, 15);
  555     assertEqualInt (status, WrongState);
  556 #endif
  557 
  558     // Get from WMF file.
  559     status = GdipSetMetafileDownLevelRasterizationLimit (wmfMetafile, 10);
  560     assertEqualInt (status, WrongState);
  561 
  562     // Negative tests.
  563     status = GdipSetMetafileDownLevelRasterizationLimit (NULL, 5);
  564     assertEqualInt (status, InvalidParameter);
  565 
  566     // FIXME: GDI+ returns WrongState.
  567 #if defined(USE_WINDOWS_GDIPLUS)
  568     status = GdipSetMetafileDownLevelRasterizationLimit (emfMetafile, -1);
  569     assertEqualInt (status, WrongState);
  570 #endif
  571 
  572     GdipDisposeImage (wmfMetafile);
  573     GdipDisposeImage (emfMetafile);
  574 }
  575 
  576 static void test_playMetafileRecord ()
  577 {
  578     GpStatus status;
  579     GpMetafile *emfMetafile;
  580     GpMetafile *wmfMetafile;
  581     BYTE data[] = {1};
  582 
  583     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  584     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  585 
  586     // Negative tests.
  587     status = GdipPlayMetafileRecord (NULL, EmfPlusRecordTypeClear, 0, 1, data);
  588     assertEqualInt (status, InvalidParameter);
  589 
  590     status = GdipPlayMetafileRecord (emfMetafile, EmfPlusRecordTypeClear, 0, 1, NULL);
  591     assertEqualInt (status, InvalidParameter);
  592 
  593     GdipDisposeImage (wmfMetafile);
  594     GdipDisposeImage (emfMetafile);
  595 }
  596 
  597 static void test_recordMetafile ()
  598 {
  599     GpStatus status;
  600     GpMetafile *wmfMetafile;
  601     GpMetafile *emfMetafile;
  602     GpImage *bitmap;
  603     GpGraphics *graphics;
  604     HDC hdc;
  605     GpRectF rect = {5, 10, 30, 40};
  606     GpRectF zeroWidth = {0, 0, 0, 100};
  607     GpRectF zeroHeight = {0, 0, 100, 0};
  608     GpMetafile *metafile;
  609 
  610     GdipCreateMetafileFromFile (wmfFilePath, &wmfMetafile);
  611     GdipCreateMetafileFromFile (emfFilePath, &emfMetafile);
  612 
  613     GdipCreateBitmapFromScan0 (10, 10, 0, PixelFormat32bppRGB, NULL, (GpBitmap **) &bitmap);
  614     GdipGetImageGraphicsContext (bitmap, &graphics);
  615     GdipGetDC (graphics, &hdc);
  616 
  617     // FIXME: this returns Ok with GDI+.
  618 #if defined(USE_WINDOWS_GDIPLUS)
  619     status = GdipRecordMetafile (hdc, EmfTypeEmfPlusDual, NULL, MetafileFrameUnitPixel, wmfFilePath, &metafile);
  620     assertEqualInt (status, Ok);
  621 #endif
  622 
  623     // Negative tests.
  624     status = GdipRecordMetafile (NULL, EmfTypeEmfPlusDual, &rect, MetafileFrameUnitPixel, wmfFilePath, &metafile);
  625     assertEqualInt (status, InvalidParameter);
  626 
  627     status = GdipRecordMetafile (hdc, (EmfType)(EmfTypeEmfOnly - 1), &rect, MetafileFrameUnitPixel, wmfFilePath, &metafile);
  628     assertEqualInt (status, InvalidParameter);
  629 
  630     status = GdipRecordMetafile (hdc, (EmfType)(EmfTypeEmfPlusDual + 1), &rect, MetafileFrameUnitPixel, wmfFilePath, &metafile);
  631     assertEqualInt (status, InvalidParameter);
  632 
  633     status = GdipRecordMetafile (hdc, EmfTypeEmfPlusDual, &rect, (MetafileFrameUnit)(MetafileFrameUnitPixel - 1), wmfFilePath, &metafile);
  634     assertEqualInt (status, InvalidParameter);
  635 
  636     status = GdipRecordMetafile (hdc, EmfTypeEmfPlusDual, &rect, (MetafileFrameUnit)(MetafileFrameUnitGdi + 1), wmfFilePath, &metafile);
  637     assertEqualInt (status, InvalidParameter);
  638 
  639     status = GdipRecordMetafile (hdc, EmfTypeEmfPlusDual, &zeroWidth, MetafileFrameUnitPixel, wmfFilePath, &metafile);
  640     assertEqualInt (status, GenericError);
  641 
  642     status = GdipRecordMetafile (hdc, EmfTypeEmfPlusDual, &zeroHeight, MetafileFrameUnitPixel, wmfFilePath, &metafile);
  643     assertEqualInt (status, GenericError);
  644 
  645     status = GdipRecordMetafile (hdc, EmfTypeEmfPlusDual, &rect, MetafileFrameUnitPixel, wmfFilePath, NULL);
  646     assertEqualInt (status, InvalidParameter);
  647 
  648     GdipDisposeImage (wmfMetafile);
  649     GdipDisposeImage (emfMetafile);
  650     GdipDisposeImage (bitmap);
  651     GdipDeleteGraphics (graphics);
  652 }
  653 
  654 int
  655 main (int argc, char**argv)
  656 {
  657     STARTUP;
  658 
  659     test_createMetafileFromFile ();
  660     test_createMetafileFromStream ();
  661     test_createMetafileFromEmf ();
  662     test_createMetafileFromWmf ();
  663     test_getMetafileHeaderFromWmf ();
  664     test_getMetafileHeaderFromEmf ();
  665     test_getMetafileHeaderFromFile ();
  666     test_getMetafileHeaderFromStream ();
  667     test_getMetafileHeaderFromMetafile ();
  668     test_gettHemfFromMetafile ();
  669     test_getMetafileDownLevelRasterizationLimit ();
  670     test_setMetafileDownLevelRasterizationLimit ();
  671     test_playMetafileRecord ();
  672     test_recordMetafile ();
  673 
  674     SHUTDOWN;
  675     return 0;
  676 }