Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Conversation

@ACEmilG
Copy link
Contributor

@ACEmilG ACEmilG commented Mar 9, 2018

Add testing for base64 encoding. Remove base64 decoding from header file to reflect its commented out implementation.

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Please try to apply each comment everywhere it makes sense.

src/base64.h Outdated
std::string Encode(const std::string &source);

std::string Decode(const std::string &source);
//std::string Decode(const std::string &source);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to comment this out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition is commented out, so I thought I would reflect that in the header file. It seemed wrong to have a declaration with no definition anywhere.

I don't feel tied to this - happy to change it back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's uncomment this. To be honest, I've also uncommented the implementation and tested it in my private clone, and it works fine, so we might as well make it available, even if we don't yet use it.
Want me to push the commit that does that?

test/Makefile Outdated
TEST_OBJS=$(TEST_SOURCES:$(TEST_DIR)/%.cc=%.o)
TESTS=\
format_unittest
format_unittest\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a space before the \.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

namespace {

TEST(EncodeTest, EmptyEncode) {
const std::string empty_str("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be worth naming the constants... How about just inlining them into the EXPECT_EQ? I.e.,

TEST (EncodeTest, EmptyEncode) {
  EXPECT_EQ("", base64::Encode(""));
}

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - done.

);
}

TEST(EncodeTest, NoPaddingEncode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add a comment explaining the "no padding" bit? E.g., // 5 bytes should produce 7 characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to come up with a good name for the "padding" tests... The best I got so far is "phantom" (as in "phantom characters at the end"). So this test would have been named "OnePhantom", and the double padding one below would become "TwoPhantoms". WDYT? Happy to hear suggestions for better names. Ultimately, I think we ought to explain what we're testing in a comment if the test name isn't sufficiently expressive.
Your comment explains "no padding", but not the difference between the single and double pad characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phantom sounds good to me. Hopefully the new comment is more clear.

);
}

TEST(EncodeTest, NoDoublePaddingEncode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "double padding"? Can you please elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure: Typically this would have "==" as padding, hence the "double" as opposed to the above which would have "=" (single). I guess its kind of a trivial case, happy to remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's an important corner case and needs to be tested, but see my other note about test naming.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed above.

src/base64.h Outdated
std::string Encode(const std::string &source);

std::string Decode(const std::string &source);
//std::string Decode(const std::string &source);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's uncomment this. To be honest, I've also uncommented the implementation and tested it in my private clone, and it works fine, so we might as well make it available, even if we don't yet use it.
Want me to push the commit that does that?

namespace {

TEST(EncodeTest, EmptyEncode) {
EXPECT_EQ(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's save some vertical space and put this whole EXPECT_EQ on a single line. Ditto below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed.

);
}

//Base64 encodings typically pad messages to ensure output length % 4 == 0, our
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing space after comment marker.

}

//Base64 encodings typically pad messages to ensure output length % 4 == 0, our
//implementation does not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing trailing ".".

);
}

TEST(EncodeTest, NoPaddingEncode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to come up with a good name for the "padding" tests... The best I got so far is "phantom" (as in "phantom characters at the end"). So this test would have been named "OnePhantom", and the double padding one below would become "TwoPhantoms". WDYT? Happy to hear suggestions for better names. Ultimately, I think we ought to explain what we're testing in a comment if the test name isn't sufficiently expressive.
Your comment explains "no padding", but not the difference between the single and double pad characters.

);
}

TEST(EncodeTest, NoDoublePaddingEncode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's an important corner case and needs to be tested, but see my other note about test naming.

}

// Base64 encoders typically pad messages to ensure output length % 4 == 0. To
// acheive this, encoders will pad messages with either one or two "=". Our
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick to one space after "." (throughout).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

Copy link
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very minor comment., otherwise LGTM.

}

// Base64 encoders typically pad messages to ensure output length % 4 == 0. To
// acheive this, encoders will pad messages with either one or two "=". Our
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acheive -> achieve

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit: again.

@igorpeshansky igorpeshansky merged commit 39932b0 into master Mar 13, 2018
@igorpeshansky igorpeshansky deleted the ACEmilG-base64-unit-tests branch March 13, 2018 12:52
igorpeshansky pushed a commit that referenced this pull request Mar 13, 2018
Also fix bug in alternate base64::Encode implementation and enable base64::Decode.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants