Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add string array tests #1041

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions src/Native/GirTestLib/girtest-string-array-tester.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include "girtest-string-array-tester.h"

/**
* GirTestStringArrayTester:
*
* Contains functions for testing bindings with string arrays.
*/

const char* data[] = { "FOO", "BAR", NULL };

struct _GirTestStringArrayTester
{
GObject parent_instance;
};

G_DEFINE_TYPE(GirTestStringArrayTester, girtest_string_array_tester, G_TYPE_OBJECT)

static void
girtest_string_array_tester_init(GirTestStringArrayTester *value)
{
}

static void
girtest_string_array_tester_class_init(GirTestStringArrayTesterClass *class)
{
}

/**
* girtest_string_array_tester_utf8_return_transfer_none:
*
* Returns an array.
*
* Returns: (transfer none): The array
*/
const char** girtest_string_array_tester_utf8_return_transfer_none()
{
return data;
}

/**
* girtest_string_array_tester_filename_return_transfer_none:
*
* Returns an array.
*
* Returns: (transfer none) (element-type filename): The array
*/
const char** girtest_string_array_tester_filename_return_transfer_none()
{
return data;
}

/**
* girtest_string_array_tester_utf8_return_transfer_none_nullable:
*
* Returns an array.
*
* Returns: (transfer none) (nullable): The array
*/
const char** girtest_string_array_tester_utf8_return_transfer_none_nullable(gboolean return_null)
{
if(return_null)
return NULL;

return data;
}

/**
* girtest_string_array_tester_filename_return_transfer_none_nullable:
*
* Returns an array.
*
* Returns: (transfer none) (element-type filename) (nullable): The array
*/
const char** girtest_string_array_tester_filename_return_transfer_none_nullable(gboolean return_null)
{
if(return_null)
return NULL;

return data;
}

/**
* girtest_string_array_tester_utf8_return_element_parameter_null_terminated_transfer_none:
* @data: (array zero-terminated=1) (element-type utf8) (transfer none): Array
* @position: The index to return
*
* Returns the string at the given position.
*
* Returns: (transfer full): The string of the array from the given position
*/
gchar* girtest_string_array_tester_utf8_return_element_parameter_null_terminated_transfer_none(const gchar** data, int position)
{
return g_strdup(data[position]);
}

/**
* girtest_string_array_tester_utf8_return_element_parameter_null_terminated_transfer_none_nullable:
* @data: (array zero-terminated=1) (element-type utf8) (transfer none) (nullable): Array
* @position: The index to return
*
* Returns the string at the given position.
*
* Returns: (transfer full) (nullable): The string of the array from the given position
*/
gchar* girtest_string_array_tester_utf8_return_element_parameter_null_terminated_transfer_none_nullable(const gchar** data, int position)
{
if(!data)
return NULL;

return g_strdup(data[position]);
}

/**
* girtest_string_array_tester_filename_return_element_parameter_null_terminated_transfer_none:
* @data: (array zero-terminated=1) (element-type filename) (transfer none): Array
* @position: The index to return
*
* Returns the string at the given position.
*
* Returns: (transfer full) (type filename): The string of the array from the given position
*/
gchar* girtest_string_array_tester_filename_return_element_parameter_null_terminated_transfer_none(const gchar** data, int position)
{
return g_strdup(data[position]);
}

/**
* girtest_string_array_tester_filename_return_element_parameter_null_terminated_transfer_none_nullable:
* @data: (array zero-terminated=1) (element-type filename) (transfer none) (nullable): Array
* @position: The index to return
*
* Returns the string at the given position.
*
* Returns: (transfer full) (type filename) (nullable): The string of the array from the given position
*/
gchar* girtest_string_array_tester_filename_return_element_parameter_null_terminated_transfer_none_nullable(const gchar** data, int position)
{
if(!data)
return NULL;

return g_strdup(data[position]);
}
20 changes: 20 additions & 0 deletions src/Native/GirTestLib/girtest-string-array-tester.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <glib-object.h>

G_BEGIN_DECLS

#define GIRTEST_TYPE_STRING_ARRAY_TESTER girtest_string_array_tester_get_type()

G_DECLARE_FINAL_TYPE(GirTestStringArrayTester, girtest_string_array_tester,
GIRTEST, STRING_ARRAY_TESTER, GObject)

const char** girtest_string_array_tester_utf8_return_transfer_none();
const char** girtest_string_array_tester_filename_return_transfer_none();
const char** girtest_string_array_tester_utf8_return_transfer_none_nullable(gboolean return_null);
const char** girtest_string_array_tester_filename_return_transfer_none_nullable(gboolean return_null);
gchar* girtest_string_array_tester_utf8_return_element_parameter_null_terminated_transfer_none(const gchar** data, int position);
gchar* girtest_string_array_tester_filename_return_element_parameter_null_terminated_transfer_none(const gchar** data, int position);
gchar* girtest_string_array_tester_utf8_return_element_parameter_null_terminated_transfer_none_nullable(const gchar** data, int position);
gchar* girtest_string_array_tester_filename_return_element_parameter_null_terminated_transfer_none_nullable(const gchar** data, int position);
G_END_DECLS
1 change: 1 addition & 0 deletions src/Native/GirTestLib/girtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "girtest-rename-to-tester.h"
#include "girtest-returning-signal-tester.h"
#include "girtest-signal-tester.h"
#include "girtest-string-array-tester.h"
#include "girtest-string-tester.h"
#include "girtest-typed-record-tester.h"
#include "girtest-untyped-record-tester.h"
Expand Down
2 changes: 2 additions & 0 deletions src/Native/GirTestLib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ header_files = [
'girtest-rename-to-tester.h',
'girtest-returning-signal-tester.h',
'girtest-signal-tester.h',
'girtest-string-array-tester.h',
'girtest-string-tester.h',
'girtest-typed-record-tester.h',
'girtest-untyped-record-tester.h',
Expand All @@ -46,6 +47,7 @@ source_files = [
'girtest-rename-to-tester.c',
'girtest-returning-signal-tester.c',
'girtest-signal-tester.c',
'girtest-string-array-tester.c',
'girtest-string-tester.c',
'girtest-typed-record-tester.c',
'girtest-untyped-record-tester.c',
Expand Down
72 changes: 72 additions & 0 deletions src/Tests/Libs/GirTest-0.1.Tests/StringArrayTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GirTest.Tests;

[TestClass, TestCategory("BindingTest")]
public class StringArrayTest : Test
{
[TestMethod]
public void Utf8ReturnNullTerminatedStringArrayTransferNone()
{
var array = new[] { "FOO", "BAR" };
StringArrayTester.Utf8ReturnTransferNone().Should().BeEquivalentTo(array);
}

[TestMethod]
public void Utf8ReturnNullTerminatedStringArrayTransferNoneNullable()
{
var array = new[] { "FOO", "BAR" };
StringArrayTester.Utf8ReturnTransferNoneNullable(false).Should().BeEquivalentTo(array);
StringArrayTester.Utf8ReturnTransferNoneNullable(true).Should().BeNull();
}

[TestMethod]
public void Utf8ParameterNullTerminatedStringArrayTransferNone()
{
var array = new[] { "FOO", "BAR" };
StringArrayTester.Utf8ReturnElementParameterNullTerminatedTransferNone(array, 0).Should().Be(array[0]);
StringArrayTester.Utf8ReturnElementParameterNullTerminatedTransferNone(array, 1).Should().Be(array[1]);
}

[TestMethod]
public void Utf8ParameterNullTerminatedStringArrayTransferNoneNullable()
{
var array = new[] { "FOO", "BAR" };
StringArrayTester.Utf8ReturnElementParameterNullTerminatedTransferNoneNullable(array, 0).Should().Be(array[0]);
StringArrayTester.Utf8ReturnElementParameterNullTerminatedTransferNoneNullable(array, 1).Should().Be(array[1]);
StringArrayTester.Utf8ReturnElementParameterNullTerminatedTransferNoneNullable(null, 1).Should().BeNull();
}

[TestMethod]
public void PlatformReturnNullTerminatedStringArrayTransferNone()
{
var array = new[] { "FOO", "BAR" };
StringArrayTester.FilenameReturnTransferNone().Should().BeEquivalentTo(array);
}

[TestMethod]
public void PlatformReturnNullTerminatedStringArrayTransferNoneNullable()
{
var array = new[] { "FOO", "BAR" };
StringArrayTester.FilenameReturnTransferNoneNullable(false).Should().BeEquivalentTo(array);
StringArrayTester.FilenameReturnTransferNoneNullable(true).Should().BeNull();
}

[TestMethod]
public void PlatformParameterNullTerminatedStringArrayTransferNone()
{
var array = new[] { "FOO", "BAR" };
StringArrayTester.FilenameReturnElementParameterNullTerminatedTransferNone(array, 0).Should().Be(array[0]);
StringArrayTester.FilenameReturnElementParameterNullTerminatedTransferNone(array, 1).Should().Be(array[1]);
}

[TestMethod]
public void PlatformParameterNullTerminatedStringArrayTransferNoneNullable()
{
var array = new[] { "FOO", "BAR" };
StringArrayTester.FilenameReturnElementParameterNullTerminatedTransferNoneNullable(array, 0).Should().Be(array[0]);
StringArrayTester.FilenameReturnElementParameterNullTerminatedTransferNoneNullable(array, 1).Should().Be(array[1]);
StringArrayTester.FilenameReturnElementParameterNullTerminatedTransferNoneNullable(null, 1).Should().BeNull();
}
}
Loading