mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Test for constructor not called.
This commit is contained in:
1 parent
aa46c5479e
commit
1db9602294
4 files changed
+45
-13
No files matched your search
@@ -44,8 +44,9 @@ func (g *Generator) Generate(pkgName string, m *t.IDMap, files []*a.File) ([]byt
|
||||
fmt.Fprintf(b, "puffs_%s_status_ok = 0,\n", pkgName)
|
||||
fmt.Fprintf(b, "puffs_%s_error_bad_version = -2 + 1,\n", pkgName)
|
||||
fmt.Fprintf(b, "puffs_%s_error_null_receiver = -4 + 1,\n", pkgName)
|
||||
fmt.Fprintf(b, "puffs_%s_status_short_dst = -6,\n", pkgName)
|
||||
fmt.Fprintf(b, "puffs_%s_status_short_src = -8,\n", pkgName)
|
||||
fmt.Fprintf(b, "puffs_%s_error_constructor_not_called= -6 + 1,\n", pkgName)
|
||||
fmt.Fprintf(b, "puffs_%s_status_short_dst = -8,\n", pkgName)
|
||||
fmt.Fprintf(b, "puffs_%s_status_short_src = -10,\n", pkgName)
|
||||
fmt.Fprintf(b, "} puffs_%s_status;\n\n", pkgName)
|
||||
|
||||
b.WriteString("// ---------------- Public Structs\n\n")
|
||||
@@ -230,6 +231,8 @@ func writeFuncImpl(b *bytes.Buffer, pkgName string, m *t.IDMap, n *a.Func) error
|
||||
writeFuncSignature(b, pkgName, m, n)
|
||||
b.WriteString("{\n")
|
||||
|
||||
cleanup0 := false
|
||||
|
||||
// Check the previous status and the args.
|
||||
if n.Public() {
|
||||
if n.Receiver() != 0 {
|
||||
@@ -240,20 +243,30 @@ func writeFuncImpl(b *bytes.Buffer, pkgName string, m *t.IDMap, n *a.Func) error
|
||||
fmt.Fprintf(b, "puffs_%s_status status = ", pkgName)
|
||||
if n.Receiver() != 0 {
|
||||
fmt.Fprintf(b, "self->status;\n")
|
||||
if n.Public() {
|
||||
fmt.Fprintf(b, "if (status & 1) { return status; }")
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(b, "puffs_%s_status_ok;\n", pkgName)
|
||||
}
|
||||
if n.Public() {
|
||||
fmt.Fprintf(b, "if (self->magic != PUFFS_MAGIC) {"+
|
||||
"status = puffs_%s_error_constructor_not_called; goto cleanup0; }", pkgName)
|
||||
cleanup0 = true
|
||||
}
|
||||
} else if r := n.Receiver(); r != 0 {
|
||||
// TODO: fix this.
|
||||
return fmt.Errorf(`cannot convert Puffs function "%s.%s" to C`, r.String(m), n.Name().String(m))
|
||||
}
|
||||
if n.Public() {
|
||||
fmt.Fprintf(b, "if (status & 1) { return status; }")
|
||||
}
|
||||
// TODO: check the args.
|
||||
b.WriteString("\n")
|
||||
|
||||
// TODO: generate the function body.
|
||||
|
||||
b.WriteString("\n")
|
||||
if cleanup0 {
|
||||
fmt.Fprintf(b, "cleanup0: self->status = status;\n")
|
||||
}
|
||||
if n.Suspendible() {
|
||||
fmt.Fprintf(b, "return status;\n")
|
||||
}
|
||||
|
||||
+10
-2
@@ -39,8 +39,9 @@ typedef enum {
|
||||
puffs_gif_status_ok = 0,
|
||||
puffs_gif_error_bad_version = -2 + 1,
|
||||
puffs_gif_error_null_receiver = -4 + 1,
|
||||
puffs_gif_status_short_dst = -6,
|
||||
puffs_gif_status_short_src = -8,
|
||||
puffs_gif_error_constructor_not_called = -6 + 1,
|
||||
puffs_gif_status_short_dst = -8,
|
||||
puffs_gif_status_short_src = -10,
|
||||
} puffs_gif_status;
|
||||
|
||||
// ---------------- Public Structs
|
||||
@@ -113,5 +114,12 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self) {
|
||||
if (status & 1) {
|
||||
return status;
|
||||
}
|
||||
if (self->magic != PUFFS_MAGIC) {
|
||||
status = puffs_gif_error_constructor_not_called;
|
||||
goto cleanup0;
|
||||
}
|
||||
|
||||
cleanup0:
|
||||
self->status = status;
|
||||
return status;
|
||||
}
|
||||
+3
-2
@@ -39,8 +39,9 @@ typedef enum {
|
||||
puffs_gif_status_ok = 0,
|
||||
puffs_gif_error_bad_version = -2 + 1,
|
||||
puffs_gif_error_null_receiver = -4 + 1,
|
||||
puffs_gif_status_short_dst = -6,
|
||||
puffs_gif_status_short_src = -8,
|
||||
puffs_gif_error_constructor_not_called = -6 + 1,
|
||||
puffs_gif_status_short_dst = -8,
|
||||
puffs_gif_status_short_src = -10,
|
||||
} puffs_gif_status;
|
||||
|
||||
// ---------------- Public Structs
|
||||
|
||||
+14
-4
@@ -17,6 +17,15 @@ Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
const char* test_filename = "gif/basic.c";
|
||||
|
||||
void test_constructor_not_called() {
|
||||
puffs_gif_lzw_decoder dec;
|
||||
puffs_gif_status status = puffs_gif_lzw_decoder_decode(&dec);
|
||||
if (status != puffs_gif_error_constructor_not_called) {
|
||||
FAIL("test_null_receiver: status: got %d, want %d", status,
|
||||
puffs_gif_error_constructor_not_called);
|
||||
}
|
||||
}
|
||||
|
||||
void test_null_receiver() {
|
||||
puffs_gif_status status = puffs_gif_lzw_decoder_decode(NULL);
|
||||
if (status != puffs_gif_error_null_receiver) {
|
||||
@@ -56,8 +65,9 @@ cleanup0:
|
||||
|
||||
// The empty comments forces clang-format to place one element per line.
|
||||
test tests[] = {
|
||||
test_null_receiver, //
|
||||
test_puffs_version_bad, //
|
||||
test_puffs_version_good, //
|
||||
NULL, //
|
||||
test_constructor_not_called, //
|
||||
test_null_receiver, //
|
||||
test_puffs_version_bad, //
|
||||
test_puffs_version_good, //
|
||||
NULL, //
|
||||
};
|
||||
Reference in new issue
Block a user