mirror of
https://github.com/allankoechke/raylib-cpp.git
synced 2026-11-30 17:19:27 +00:00
105 lines
2.5 KiB
C++
105 lines
2.5 KiB
C++
#include <cassert>
|
|
#include <string>
|
|
#include <vector>
|
|
#include "raylib-cpp.hpp"
|
|
|
|
int main(int argc, char *argv[]) {
|
|
TraceLog(LOG_INFO, "TEST: raylib-cpp test");
|
|
|
|
// Get a path to where the executable is so file loading is relative.
|
|
std::string path = "";
|
|
if (argc > 0) {
|
|
path = GetDirectoryPath(argv[0]);
|
|
}
|
|
|
|
// Vector
|
|
{
|
|
raylib::Vector2 position(50, 100);
|
|
assert(position.GetX() == position.x);
|
|
position.x = 150;
|
|
assert(position.GetX() == 150);
|
|
position.SetX(300);
|
|
assert(position.GetX() == 300);
|
|
|
|
raylib::Vector2 speed(10, 10);
|
|
position += speed;
|
|
assert(position.x == 310);
|
|
assert(raylib::Window::IsReady() == false);
|
|
|
|
raylib::Vector2 size{50,50};
|
|
raylib::Vector2 halfsize = size / 2.0f;
|
|
|
|
assert(size.x == 50);
|
|
assert(halfsize.x == 25);
|
|
|
|
raylib::Vector2 doublesize = size * 2.0f;
|
|
assert(size.x == 50);
|
|
assert(doublesize.x == 100);
|
|
}
|
|
|
|
// Color
|
|
{
|
|
raylib::Color color = RED;
|
|
assert(color.ToInt() == ::ColorToInt(RED));
|
|
color = RAYWHITE;
|
|
assert(color.r == RAYWHITE.r);
|
|
}
|
|
|
|
// Math
|
|
{
|
|
raylib::Vector2 direction(50, 50);
|
|
raylib::Vector2 newDirection = direction.Rotate(30);
|
|
assert(((int)newDirection.x) == 57);
|
|
}
|
|
|
|
// raylib::GetDirectoryFiles()
|
|
{
|
|
std::vector<std::string> files = raylib::GetDirectoryFiles(::GetWorkingDirectory());
|
|
assert(files.size() > 3);
|
|
}
|
|
|
|
// raylib::TextReplace()
|
|
{
|
|
std::string input = "Hello World!";
|
|
std::string output = raylib::TextReplace(input, "World", "Moon");
|
|
assert(output == "Hello Moon!");
|
|
}
|
|
|
|
// raylib::TextInsert()
|
|
{
|
|
std::string input = "Hello World!";
|
|
std::string output = raylib::TextInsert(input, "Good!", 0);
|
|
assert(output == "Good! World!");
|
|
}
|
|
|
|
// raylib::TextSubtext()
|
|
{
|
|
std::string input = "Hello World!";
|
|
std::string output = raylib::TextSubtext(input, 6, 5);
|
|
assert(output == "World");
|
|
}
|
|
|
|
// Sound
|
|
{
|
|
raylib::Wave wave(path + "/resources/weird.wav");
|
|
assert(wave.IsReady());
|
|
}
|
|
|
|
// RaylibException
|
|
{
|
|
bool passed = false;
|
|
try {
|
|
raylib::Texture texture("notfound.png");
|
|
}
|
|
catch (raylib::RaylibException& error) {
|
|
error.TraceLog(LOG_INFO);
|
|
passed = true;
|
|
}
|
|
|
|
assert(passed);
|
|
}
|
|
|
|
TraceLog(LOG_INFO, "TEST: raylib-cpp test complete");
|
|
return 0;
|
|
}
|