Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/gfx/tests/gtest/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 6 kB image not shown  

Quelle  TestBufferRotation.cpp

  Sprache: C
 

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "gtest/gtest.h"

#include "BufferUnrotate.h"

using mozilla::gfx::BufferUnrotate;

static unsigned char* GenerateBuffer(int bytesPerPixel, int width, int height,
                                     int stride, int xBoundary, int yBoundary) {
  unsigned char* buffer = new unsigned char[stride * height];
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      int pos = ((yBoundary + y) % height) * stride +
                ((xBoundary + x) % width) * bytesPerPixel;
      for (int i = 0; i < bytesPerPixel; i++) {
        buffer[pos + i] = (x + y + i * 2) % 256;
      }
    }
  }
  return buffer;
}

static bool CheckBuffer(unsigned char* buffer, int bytesPerPixel, int width,
                        int height, int stride) {
  int xBoundary = 0;
  int yBoundary = 0;
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      int pos = ((yBoundary + y) % height) * stride +
                ((xBoundary + x) % width) * bytesPerPixel;
      for (int i = 0; i < bytesPerPixel; i++) {
        if (buffer[pos + i] != (x + y + i * 2) % 256) {
          printf("Buffer differs at %i, %i, is %i\n", x, y,
                 (int)buffer[pos + i]);
          return false;
        }
      }
    }
  }
  return true;
}

TEST(Gfx, BufferUnrotateHorizontal)
{
  const int NUM_OF_TESTS = 8;
  int bytesPerPixelList[2] = {24};
  int width[NUM_OF_TESTS] = {10010099991001009999};
  int height[NUM_OF_TESTS] = {10099100991009910099};
  int xBoundary[NUM_OF_TESTS] = {3030303031313131};
  int yBoundary[NUM_OF_TESTS] = {0000};

  for (int bytesPerId = 0; bytesPerId < 2; bytesPerId++) {
    int bytesPerPixel = bytesPerPixelList[bytesPerId];
    int stride = 256 * bytesPerPixel;
    for (int testId = 0; testId < NUM_OF_TESTS; testId++) {
      unsigned char* buffer =
          GenerateBuffer(bytesPerPixel, width[testId], height[testId], stride,
                         xBoundary[testId], yBoundary[testId]);
      BufferUnrotate(buffer, width[testId] * bytesPerPixel, height[testId],
                     stride, xBoundary[testId] * bytesPerPixel,
                     yBoundary[testId]);

      EXPECT_TRUE(CheckBuffer(buffer, bytesPerPixel, width[testId],
                              height[testId], stride));
      delete[] buffer;
    }
  }
}

TEST(Gfx, BufferUnrotateVertical)
{
  const int NUM_OF_TESTS = 8;
  int bytesPerPixelList[2] = {24};
  int width[NUM_OF_TESTS] = {10010099991001009999};
  int height[NUM_OF_TESTS] = {10099100991009910099};
  int xBoundary[NUM_OF_TESTS] = {0000};
  int yBoundary[NUM_OF_TESTS] = {3030303031313131};

  for (int bytesPerId = 0; bytesPerId < 2; bytesPerId++) {
    int bytesPerPixel = bytesPerPixelList[bytesPerId];
    int stride = 256 * bytesPerPixel;
    for (int testId = 0; testId < NUM_OF_TESTS; testId++) {
      unsigned char* buffer =
          GenerateBuffer(bytesPerPixel, width[testId], height[testId], stride,
                         xBoundary[testId], yBoundary[testId]);
      BufferUnrotate(buffer, width[testId] * bytesPerPixel, height[testId],
                     stride, xBoundary[testId] * bytesPerPixel,
                     yBoundary[testId]);

      EXPECT_TRUE(CheckBuffer(buffer, bytesPerPixel, width[testId],
                              height[testId], stride));
      delete[] buffer;
    }
  }
}

TEST(Gfx, BufferUnrotateBoth)
{
  const int NUM_OF_TESTS = 16;
  int bytesPerPixelList[2] = {24};
  int width[NUM_OF_TESTS] = {10010099991001009999,
                             10010099991001009999};
  int height[NUM_OF_TESTS] = {10099100991009910099,
                              10099100991009910099};
  int xBoundary[NUM_OF_TESTS] = {3030303031313131,
                                 3030303031313131};
  int yBoundary[NUM_OF_TESTS] = {3030303030303030,
                                 3131313131313131};

  for (int bytesPerId = 0; bytesPerId < 2; bytesPerId++) {
    int bytesPerPixel = bytesPerPixelList[bytesPerId];
    int stride = 256 * bytesPerPixel;
    for (int testId = 0; testId < NUM_OF_TESTS; testId++) {
      unsigned char* buffer =
          GenerateBuffer(bytesPerPixel, width[testId], height[testId], stride,
                         xBoundary[testId], yBoundary[testId]);
      BufferUnrotate(buffer, width[testId] * bytesPerPixel, height[testId],
                     stride, xBoundary[testId] * bytesPerPixel,
                     yBoundary[testId]);

      EXPECT_TRUE(CheckBuffer(buffer, bytesPerPixel, width[testId],
                              height[testId], stride));
      delete[] buffer;
    }
  }
}

TEST(Gfx, BufferUnrotateUneven)
{
  const int NUM_OF_TESTS = 16;
  int bytesPerPixelList[2] = {24};
  int width[NUM_OF_TESTS] = {10,  1009939100409939,
                             10050,  399974,  609939};
  int height[NUM_OF_TESTS] = {1003910,  9910994099,
                              73,  391003967998499};
  int xBoundary[NUM_OF_TESTS] = {0,  0,  303099310,  31,
                                 3030303031313138};
  int yBoundary[NUM_OF_TESTS] = {30300,  300,  300,  30,
                                 3131313131313198};

  for (int bytesPerId = 0; bytesPerId < 2; bytesPerId++) {
    int bytesPerPixel = bytesPerPixelList[bytesPerId];
    int stride = 256 * bytesPerPixel;
    for (int testId = 0; testId < NUM_OF_TESTS; testId++) {
      unsigned char* buffer =
          GenerateBuffer(bytesPerPixel, width[testId], height[testId], stride,
                         xBoundary[testId], yBoundary[testId]);
      BufferUnrotate(buffer, width[testId] * bytesPerPixel, height[testId],
                     stride, xBoundary[testId] * bytesPerPixel,
                     yBoundary[testId]);

      EXPECT_TRUE(CheckBuffer(buffer, bytesPerPixel, width[testId],
                              height[testId], stride));
      delete[] buffer;
    }
  }
}

Messung V0.5 in Prozent
C=99 H=97 G=97

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.