Verified Commit 558ba565 authored by RobLoach's avatar RobLoach
Browse files

tests: Clean up the tests

parent 1519837f
......@@ -77,9 +77,6 @@ cpplint: vendor/libretro-common/include/libretro.h
tests: vendor/libretro-common/include/libretro.h
$(MAKE) HAVE_CHAISCRIPT=0 HAVE_TESTS=1
test-native: tests
retroarch -L $(TARGET) test/native/main.chai
PREFIX := /usr
INSTALLDIR := $(PREFIX)/lib/libretro
install: all
......
......@@ -7,7 +7,6 @@ SOURCES_CXX := $(wildcard \
$(CORE_DIR)/src/love/Types/Graphics/*.cpp \
$(CORE_DIR)/src/love/Types/Input/*.cpp \
$(CORE_DIR)/src/love/Types/Config/*.cpp \
$(CORE_DIR)/test/native/*.cpp \
)
# semver
......@@ -168,7 +167,3 @@ OBJECTS += $(SOURCES_CXX:.cpp=.o) $(SOURCES_C:.c=.o)
LDFLAGS += $(fpic) $(SHARED) $(EXTRA_LDF)
WARNINGS :=
ifneq ($(HAVE_TESTS),)
FLAGS += -D__HAVE_TESTS__
endif
......@@ -55,11 +55,6 @@ bool ChaiLove::load(const std::string& file) {
script->conf(config);
system.load(config);
// Testing.
#ifdef __HAVE_TESTS__
test.conf(config);
#endif
// Load up the window dimensions.
window.load(config);
......@@ -80,10 +75,6 @@ bool ChaiLove::load(const std::string& file) {
// Now that all subsystems are loaded, start the script.
script->load();
#ifdef __HAVE_TESTS__
test.load();
#endif
return true;
}
......@@ -133,18 +124,15 @@ std::string ChaiLove::demo() {
}
bool ChaiLove::update() {
if (event.m_quitstatus) {
return false;
}
sound.update();
// Poll all the inputs.
ChaiLove::input_poll_cb();
// Poll all SDL events.
while (SDL_PollEvent(&sdlEvent)) {
switch (sdlEvent.type) {
case SDL_QUIT:
event.quit();
return !event.m_quitstatus;
return !event.m_shouldclose;
break;
}
}
......@@ -157,11 +145,7 @@ bool ChaiLove::update() {
// Step forward the timer, and update the game.
script->update(timer.getDelta());
#ifdef __HAVE_TESTS__
test.update(timer.getDelta());
#endif
return !event.m_quitstatus;
return !event.m_shouldclose;
}
/**
......@@ -184,10 +168,6 @@ void ChaiLove::draw() {
// Render the game.
script->draw();
#ifdef __HAVE_TESTS__
test.draw();
#endif
// Render the in-game console.
console.draw();
......
......@@ -60,10 +60,6 @@
#include "love/event.h"
#include "love/console.h"
#ifdef __HAVE_TESTS__
#include "../test/native/NativeTest.h"
#endif
class ChaiLove {
public:
static ChaiLove* getInstance();
......@@ -105,10 +101,6 @@ class ChaiLove {
uint32_t *videoBuffer;
SDL_Surface* screen;
SDL_Event sdlEvent;
#ifdef __HAVE_TESTS__
NativeTest test;
#endif
};
#endif // SRC_CHAILOVE_H_
......@@ -10,7 +10,7 @@ const char *retro_save_directory;
const char *retro_system_directory;
const char *retro_content_directory;
static bool use_audio_cb;
int16_t audio_buffer[2 * (44100 / 60)];
int16_t audio_buffer[1470]; // 2 * (44100 / 60)
static retro_video_refresh_t video_cb;
retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
......@@ -38,7 +38,7 @@ void retro_set_input_state(retro_input_state_t cb) {
static void emit_audio(void) {
ChaiLove* app = ChaiLove::getInstance();
app->audio.mixer_render(audio_buffer);
audio_batch_cb(audio_buffer, (44100 / 60));
audio_batch_cb(audio_buffer, 735); // 44100 / 60
}
static void audio_set_state(bool enable) {
......@@ -90,7 +90,7 @@ void retro_set_environment(retro_environment_t cb) {
}
/**
* libretro callback; Updates the system variables.
* libretro callback; Updates the core option variables.
*/
static void update_variables(void) {
ChaiLove* game = ChaiLove::getInstance();
......@@ -462,9 +462,9 @@ void retro_reset(void) {
*/
void retro_run(void) {
ChaiLove* app = ChaiLove::getInstance();
if (!app->event.m_quitstatus) {
// Poll all the inputs.
ChaiLove::input_poll_cb();
if (app->event.m_shouldclose) {
return;
}
// Update the game.
if (!app->update()) {
......@@ -477,5 +477,4 @@ void retro_run(void) {
// Copy the video buffer to the screen.
video_cb(app->videoBuffer, app->config.window.width, app->config.window.height, app->config.window.width << 2);
}
}
......@@ -24,7 +24,7 @@ namespace love {
* t.window.title = "My Game" // Human-readable name
* t.window.width = 1024 // Game width
* t.window.height = 768 // Game height
* t.console = false // Developer console
* t.console = false // Developer console, toggle with tilde
* }
* @endcode
*/
......
......@@ -3,7 +3,7 @@
namespace love {
void event::quit() {
m_quitstatus = true;
m_shouldclose = true;
}
} // namespace love
......@@ -8,10 +8,10 @@ namespace love {
class event {
public:
/**
* Exits ChaiLove.
* Exits the ChaiLove application.
*/
void quit();
bool m_quitstatus = false;
bool m_shouldclose = false;
};
} // namespace love
......
......@@ -14,10 +14,6 @@ bool sound::load() {
return true;
}
bool sound::update() {
return true;
}
void sound::unload() {
// Unload all sounds.
for (std::vector<SoundData*>::size_type i = 0; i != sounds.size(); i++) {
......
......@@ -14,7 +14,6 @@ class sound {
bool load();
bool hasAudio();
void unload();
bool update();
/**
* Creates a new SoundData.
......
class filesystem_getDirectoryItems {
var name;
var x;
var y;
var files;
def filesystem_getDirectoryItems() {
this.name = "filesystem.getDirectoryItems()";
}
def load() {
this.x = 100;
this.y = love.graphics.getHeight() / 3.0f;
this.files = love.filesystem.getDirectoryItems("/")
}
def draw() {
var y = this.y
for (file : this.files) {
love.graphics.print("- " + file, this.x, y)
y += 10
}
}
def update(delta) {
}
};
......@@ -6,8 +6,7 @@ global testNames = [
"graphics_draw",
"graphics_point",
"mouse_getPosition",
"graphics_print_font",
"filesystem_getDirectoryItems"
"graphics_print_font"
]
global tests = []
global currenttest = 0
......
/**
* ChaiLove: Native Tests
*
* Tests some of the usage of ChaiLove without the need of scripts.
*
* Usage: make test-native
*/
#ifdef __HAVE_TESTS__
#include "NativeTest.h"
#include "../../src/ChaiLove.h"
using love::config;
void NativeTest::conf(config& t) {
t.window.width = 1080;
t.window.height = 768;
}
bool NativeTest::load() {
ChaiLove* app = ChaiLove::getInstance();
app->filesystem.mount("test", "/");
secondfont = app->graphics.newFont("assets/Raleway-Regular.ttf", 60);
thefont = app->graphics.newFont("assets/c64_16x16.png", 16, 16, "\x7f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
img = app->graphics.newImage("assets/graphics_draw.png");
jump = app->sound.newSoundData("assets/jump.wav");
}
void NativeTest::update(float delta) {
ChaiLove* app = ChaiLove::getInstance();
if (app->joystick.isDown(0, 0) && !jump->isPlaying()) {
app->audio.play(jump);
}
}
void NativeTest::draw() {
ChaiLove* app = ChaiLove::getInstance();
app->graphics.setColor(77, 182, 172);
app->graphics.ellipse("fill", 0, 768, 200, 180);
int width = thefont->getWidth("Bitmap Commodore Font!");
int height = app->graphics.getHeight() / 2.0f - thefont->getHeight() / 2.0f;
app->graphics.setColor(100, 181, 246);
app->graphics.setFont(thefont);
app->graphics.print("Bitmap Commodore Font!", app->graphics.getWidth() / 2.0f - width / 2.0f, 200);
app->graphics.setColor(255, 181, 0);
app->graphics.setFont(secondfont);
width = secondfont->getWidth("TTF Font here!");
height = app->graphics.getHeight() / 2.0f - secondfont->getHeight() / 2.0f;
app->graphics.print("TTF Font here!", app->graphics.getWidth() / 2.0f - width / 2.0f, height);
app->graphics.draw(img, 100, 100);
}
#endif
#ifdef __HAVE_TESTS__
#ifndef CHAILOVE_TEST_NATIVE_NATIVETEST_H
#define CHAILOVE_TEST_NATIVE_NATIVETEST_H
#include "../../src/love/Types/Graphics/Image.h"
#include "../../src/love/Types/Graphics/Font.h"
#include "../../src/love/config.h"
#include "../../src/love/Types/Audio/SoundData.h"
using love::Types::Graphics::Image;
using love::Types::Graphics::Font;
using love::config;
using love::Types::Audio::SoundData;
class NativeTest {
public:
void conf(config& t);
bool load();
void update(float delta);
void draw();
int tester = 0;
Font* thefont;
Font* secondfont;
SoundData* jump;
Image* img;
};
#endif
#endif
# Native Tests
This provides some native tests to call ChaiLove directly through C++.
## Usage
```
make test-native
```
...or...
```
make tests
retroarch -L chailove_libretro.so test/native/main.chai
```
def draw() {
love.graphics.print("See NativeTests.cpp for the test cases", 5, 5)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment