From cb3ab4c90d71d40c9c3f5a37bac0c274e8c89cbb Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 31 Oct 2023 12:13:48 +0100 Subject: [PATCH 1/2] Add String::isEmpty() --- api/String.h | 1 + 1 file changed, 1 insertion(+) diff --git a/api/String.h b/api/String.h index 73a872de..0bafd35a 100644 --- a/api/String.h +++ b/api/String.h @@ -89,6 +89,7 @@ class String // invalid string (i.e., "if (s)" will be true afterwards) bool reserve(unsigned int size); inline unsigned int length(void) const {return len;} + inline bool isEmpty(void) const { return length() == 0; } // creates a copy of the assigned value. if the value is null or // invalid, or if the memory allocation fails, the string will be From 73e2d09d7d9d11b81071e70745a539a412a226f4 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 7 Nov 2023 18:20:31 +0100 Subject: [PATCH 2/2] Add unit test for String::isEmpty() --- test/src/String/test_isEmpty.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/src/String/test_isEmpty.cpp diff --git a/test/src/String/test_isEmpty.cpp b/test/src/String/test_isEmpty.cpp new file mode 100644 index 00000000..9f70f26d --- /dev/null +++ b/test/src/String/test_isEmpty.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +#include "StringPrinter.h" + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Testing String::isEmpty when string is empty", "[String-isEmpty-01]") +{ + arduino::String str; + REQUIRE(str.isEmpty()); +} + +TEST_CASE ("Testing String::isEmpty when string contains characters", "[String-isEmpty-02]") +{ + arduino::String str("Testing String::isEmpty"); + REQUIRE(!str.isEmpty()); +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy