trivial: Use the shared fu_test_compare_lines() in the dfu plugin

This commit is contained in:
Richard Hughes 2018-01-11 09:58:05 +00:00
parent 9c808e838e
commit b73e70b205
2 changed files with 7 additions and 33 deletions

View File

@ -32,7 +32,7 @@
#include "fwupd-remote-private.h"
static gboolean
as_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
fu_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
{
g_autofree gchar *output = NULL;
@ -240,7 +240,7 @@ fwupd_device_func (void)
g_assert (fwupd_device_has_guid (dev, "00000000-0000-0000-0000-000000000000"));
g_assert (!fwupd_device_has_guid (dev, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));
ret = as_test_compare_lines (str,
ret = fu_test_compare_lines (str,
"ColorHug2\n"
" DeviceId: USB:foo\n"
" Guid: 2082b5e0-7a64-478a-b1b2-e3404fab6dad\n"

View File

@ -24,7 +24,6 @@
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <fnmatch.h>
#include "dfu-chunked.h"
#include "dfu-cipher-xtea.h"
@ -35,6 +34,8 @@
#include "dfu-sector-private.h"
#include "dfu-target-private.h"
#include "fu-test.h"
#include "fwupd-error.h"
static gchar *
@ -50,33 +51,6 @@ dfu_test_get_filename (const gchar *filename)
return g_strdup (full_tmp);
}
static gboolean
dfu_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
{
g_autofree gchar *output = NULL;
/* exactly the same */
if (g_strcmp0 (txt1, txt2) == 0)
return TRUE;
/* matches a pattern */
if (fnmatch (txt2, txt1, FNM_NOESCAPE) == 0)
return TRUE;
/* save temp files and diff them */
if (!g_file_set_contents ("/tmp/a", txt1, -1, error))
return FALSE;
if (!g_file_set_contents ("/tmp/b", txt2, -1, error))
return FALSE;
if (!g_spawn_command_line_sync ("diff -urNp /tmp/b /tmp/a",
&output, NULL, NULL, error))
return FALSE;
/* just output the diff */
g_set_error_literal (error, 1, 0, output);
return FALSE;
}
static gchar *
_g_bytes_compare_verbose (GBytes *bytes1, GBytes *bytes2)
{
@ -589,7 +563,7 @@ dfu_target_dfuse_func (void)
g_assert_no_error (error);
g_assert (ret);
tmp = dfu_target_sectors_to_string (target);
ret = dfu_test_compare_lines (tmp,
ret = fu_test_compare_lines (tmp,
"Zone:0, Sec#:0, Addr:0x08000000, Size:0x0400, Caps:0x1 [R]\n"
"Zone:0, Sec#:0, Addr:0x08000400, Size:0x0400, Caps:0x1 [R]",
&error);
@ -602,7 +576,7 @@ dfu_target_dfuse_func (void)
g_assert_no_error (error);
g_assert (ret);
tmp = dfu_target_sectors_to_string (target);
ret = dfu_test_compare_lines (tmp,
ret = fu_test_compare_lines (tmp,
"Zone:0, Sec#:0, Addr:0x08000000, Size:0x0400, Caps:0x1 [R]\n"
"Zone:0, Sec#:0, Addr:0x08000400, Size:0x0400, Caps:0x1 [R]\n"
"Zone:0, Sec#:1, Addr:0x08000800, Size:0x0400, Caps:0x7 [REW]\n"
@ -619,7 +593,7 @@ dfu_target_dfuse_func (void)
g_assert_no_error (error);
g_assert (ret);
tmp = dfu_target_sectors_to_string (target);
ret = dfu_test_compare_lines (tmp,
ret = fu_test_compare_lines (tmp,
"Zone:0, Sec#:0, Addr:0x0000f000, Size:0x0064, Caps:0x1 [R]\n"
"Zone:0, Sec#:0, Addr:0x0000f064, Size:0x0064, Caps:0x1 [R]\n"
"Zone:0, Sec#:0, Addr:0x0000f0c8, Size:0x0064, Caps:0x1 [R]\n"